I am trying to create a selection. First, I select records which have Null value in "Status" column ("Status" is NULL"
). Then it starts to be a bit tricky. I want to select all the records which have the same number as selected "Status" records. Is it possible to do it in QGIS?
First, I select null values using "Status" is NULL
expression.
Then I need to add something to take ID values and use it to create a new selection.
The final selection should look like that:
I am using QGIS 2.16.
Answer
You may run this code from the Python Console (it works on the active layer):
layer = iface.activeLayer()
query_1 = '"Status" is NULL'
selection = layer.getFeatures(QgsFeatureRequest().setFilterExpression(query_1))
selected_ids = [k["ID"] for k in selection]
ids = []
for feat in layer.getFeatures():
if feat["ID"] in selected_ids:
ids.append(feat.id())
layer.setSelectedFeatures([l for l in ids])
You will obtain the desired output:
No comments:
Post a Comment