Example code: layer.setSubsetString(“‘4′ LIKE “dist_code””’)

# Show every province features (postcodes) one by one

from time import sleep

def stopped(task):
    pass
def completed(exception, result=None):
    pass
def run(task, wait_time):

    # main code
    postcodes = QgsProject.instance().mapLayersByName('postcodes')[0]
    wait_time = wait_time / 100
    prov = [1, 3, 4, 5, 6]
    for i, m in enumerate(prov):
        task.setProgress(i)
        sleep(wait_time)
        postcodes.setSubsetString("'" + str(m) + "'" + ''' LIKE "dist_code"''')

        if task.isCanceled():
            stopped(task)
            return None
    postcodes.setSubsetString("")

task = QgsTask.fromFunction(u'Task', run,
                            on_finished=completed, wait_time=150)
QgsApplication.taskManager().addTask(task)

Or by right click on layer and go to Source and Query Builder:

Filter features on a layer #QGIS #PyQGIS

About

Hello all,

My name is Marios. Welcome to my page!

Marios S. Kyriakou received his B.Sc (2012) and his M.Sc. (2014) in Electrical Engineering from the Department of Electrical and Computer Engineering of the University of Cyprus. His Master Thesis with the title “Risk Evaluation and Sensor Placement for Disinfection By-Products in Water Distribution Systems” was carried out in KIOS under the supervision of Dr. Marios M. Polycarpou and Dr. Demetrios G. Eliades. He is currently working as a Software Developer at KIOS Research and Innovation Center of Excellence since 2012.  His research interests focus on water distribution systems.

Publications
Google Scholar

Active member
http://community.wateranalytics.org/

Enjoy to follow and subscribe to me, thanks!
https://www.youtube.com/user/Mariosmsk/
https://github.com/Mariosmsk

CONTACT DETAILS
E-mail: mariosmsk@gmail.com

Year, Winner
1956, Switzerland
1957, Netherlands
1958, France
1959, Netherlands
1960, France
1961, Luxembourg
1962, France
1963, Denmark
1964, Italy
1965, Luxembourg
1966, Austria
1967, United Kingdom
1968, Spain
1969, Spain
1970, Ireland
1971, Monaco
1972, Luxembourg
1973, Luxembourg
1974, Sweden
1975, Netherlands
1976, United Kingdom
1977, France
1978, Israel
1979, Israel
1980, Ireland
1981, United Kingdom
1982, Germany
1983, Luxembourg
1984, Sweden
1985, Norway
1986, Belgium
1987, Ireland
1988, Switzerland
1989, Yugoslavia
1990, Italy
1991, Sweden
1992, Ireland
1993, Ireland
1994, Ireland
1995, Norway
1996, Ireland
1997, United Kingdom
1998, Israel
1999, Sweden
2000, Denmark
2001, Estonia
2002, Latvia
2003, Turkey
2004, Ukraine
2005, Greece
2006, Finland
2007, Serbia
2008, Russia
2009, Norway
2010, Germany
2011, Azerbaijan
2012, Sweden
2013, Denmark
2014, Austria
2015, Sweden
2016, Ukraine
2017, Portugal
2018, Israel
2019, Netherlands

Example: HERE

Eurovision Winners 1956 – 2019 #QGIS #Maps #Eurovision