I found the function setSubsetOfFields to filter fields in a layer in the PyGIS cookbook:
But it seems like that these function doesn't exist in QGIS 2.4. Neither has the layer a fields() function. There is only a setSubsetOfAttributes function.
I tried to use it like this:
layer = qgis.utils.iface.activeLayer() request = QgsFeatureRequest() request.setSubsetOfFields(['id', 'name'], layer.fields()) features = layer.getFeatures(request) for feature in features: print feature.attributes()
Am I using this wrong or is there another possibillitie to set a filter on the layer fields?