Bug report #8051
setSubsetOfAttributes() doesn't work
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||all||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||wontfix|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||16892|
I try to get features within some rectangle, and want to get only some attributes without geometries. So I use next code:
request = QgsFeatureRequest() request.setFilterRect(self.extent) request.setFlags(QgsFeatureRequest.NoGeometry) request.setSubsetOfAttributes([0, 3, 6]) f = QgsFeature() fit = layer.getFeatures(request) while fit.nextFeature(f): attrs = f.attributes() # process attributes ...
but in attrs valiable I always get all feature attributes.
Confirmed also by Nathan, see http://lists.osgeo.org/pipermail/qgis-developer/2013-May/026119.html
#2 Updated by Jürgen Fischer over 6 years ago
Is this a bug or a feature?
Before each feature had a map of attribute values with the attributes field index and it's value. So you could identify each attribute no matter how the feature was retrieved. Now we have an array of attributes and the index of an attribute in that array corresponds to the field index. So by looking at the feature you still know which attribute belongs in which field. Difference is, that the feature doesn't know which attributes were actually retrieved or are just fillers to get the indices right. You can still safely assume that all requested attributes are there, with their original index. But not that only those are there.
I think the implied solution for the ticket would be to only have an attribute array with the requested attributes. That would mean that the indices of the feature attributes would change and in turn all code that implies that an retrieved attribute has the field index would need to be identified and adjusted...