I'm facing a nested problem using pyqgis (for QGIS master, but it can be replicated in any version of QGIS 2).
I have a vector layer with some selected features and with a
QgsFeatureRequest I can easily loop only on the selected features:
vl = iface.activeLayer() # get the list of selected ids ids = vl.selectedFeatureIds() # create the request with the selected ids request = QgsFeatureRequest() request.setFilterFids(ids) # use only the selected features in getFeatures for i in vl.getFeatures(request): print(i.attributes())
Then I build an expression based on a field of the attribute table and I can use
QgsFeatureRequest() to filter only the features that match that expression:
exp = ''' "Piper" = 1 ''' request = QgsFeatureRequest() request.setFilterExpression(exp) for i in vl.getFeatures(request): print(i.attributes())
but what if I want to filter with the same expression only the already selected features?
So actually use both requests in the same