I have a point PostGIS layer (my_layer) which has more than 66000 features. I am getting the features I want but it takes too long. My code is:
resultList = []
req = QgsFeatureRequest().setFilterExpression(' "some_field_name" = \'some_value\' ')
for feat in my_layer.getFeatures(req):
name = feat.attribute("some_other_field")
resultList.append(name)
How can I optimize it so that I can get the results quicker?
Answer
QGIS API provides you with a couple of ways for optimizing features requests.
In your case, if you don't need geometry and the rest of attributes in the result, you can:
- Use flag
NoGeometry
(see docs). - Set subset of attributes you really need using
setSubsetOfAttributes()
(see docs).
That should speed your request up.
No comments:
Post a Comment