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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Greg
  • 521
  • 1
  • 5
  • 14

1 Answers1

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
Poulpy
  • 11
  • 2