Is it possible to automate the following procedure with graphical modeler in qgis 3.4 or is it easier to perform such action with a python script using PyQGIS?
- Identify a feature (a line) in a vector layer using the mouse pointer, features have an attribute named RLID
- Then let the model select all features with the same attribute value in the vector layer
Right now this is done manually, a very time-consuming process. The manual process starts by identifying a feature and copying the RLID attribute value. Then the features with the same RLID value are selected using "Select features by value".
I am completely new to qgis but know how to program with python.
Speed is important since we have 200k features to process. I tried a little python script (with a selected feature) for extracting features with the same attribute value and it took 30s, which is very long time compared with F3 - Select features by value.
layer = iface.activeLayer();
features = layer.getFeatures()
selected = layer.getSelectedFeatures()
for f in selected:
rlid = f['RLID']
print(rlid)
fs = [f.id() for f in features if f['RLID'] == rlid]
print(fs)
Found by older posts that a quicker way to obtain the features fs is:
expr = QgsExpression( "\"RLID\"='"+rlid+"'" )
it = layer.getFeatures( QgsFeatureRequest( expr ) )
fs = [i.id() for i in it]