Bug report #8051

setSubsetOfAttributes() doesn't work

Added by Alexander Bruy over 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:Martin Dobias
Category:Data Provider
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

Description

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


Subtasks

Bug report #7781: selecting attributes in add attribute table in Map Compos...Closed

History

#1 Updated by Nathan Woodrow over 6 years ago

I suspect it's this

// TODO[MD]: just one resize of attributes
f.setFields( &L->mUpdatedFields );

In QgsVectorLayerFeatureIterator::nextFeature

#2 Updated by Jürgen Fischer about 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...

#3 Updated by Jürgen Fischer about 6 years ago

  • Status changed from Open to Feedback

#4 Updated by Nathan Woodrow about 6 years ago

  • Resolution set to wontfix
  • Status changed from Feedback to Closed

This is intended behavior now. The feature field list should equal the layer field list and the index should match.

Also available in: Atom PDF