I have a QgsFeatureRequest() that filter all the features by an attribute. Is there any python function that could tell me how many features were filtered? I know I could create a list with this features and then count them. But I want a better way.

1 Answer 1


This is a quite short way:

vlayer.selectByExpression("here comes your expression")

If you stick to QgsFeatureRequest(), then you have to use a counter (I guess). After vlayer.getFeatures(QgsFeatureRequest("here comes your expression")), you will have a QgsFeatureIterator, which does not have method like featureCount().



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.