1

I'm looking for an efficient way to filter my 700.000 features by attribute in PyQGIS. As suggested in this post It looks like using QgsExpression for such a job is a fastest way? Or is there a faster approach? I'm filtering using integers in indexed columns on my database.

Now when it comes to API I've noticed there is a :

for feature in layer.getFeatures(QgsFeatureRequest(QgsExpression.createFieldEqualityExpression('field_name', value))): 

do something with feature

Any speed up suggestions? Is using list comprehension with filtering faster way to go about this problem?

1 Answer 1

1

createFieldEqualityExpression return a string so I was able to use it as such:

features = layer.getFeatures(QgsFeatureRequest().setFilterExpression(QgsExpression.createFieldEqualityExpression(field_name, value)))
for feat in features:
    #code using the features
    pass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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