1

How to get a particular feature using an expression in PyQGIS?

For example, there are 100 houses (with 100 entries in Attributes Table). I want to get only one house with field name ("name"=="John's House") and make get selected that feature in the map view.

4
layer = iface.activeLayer()

layer.selectByExpression('"name"=\'John's House\'', QgsVectorLayer.SetSelection)

selection = layer.selectedFeatures()

print(len(selection))

References:

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.