[Qgis-developer] Help with QgsVectorLayer
Marco Hugentobler
marco.hugentobler at karto.baug.ethz.ch
Mon Mar 12 14:03:30 EDT 2007
Hi Peter,
I suppose the reason is that QGIS does only read the attributes from the
provider it needs for drawing. If you have e.g. style single symbol, then
only the geometry is copied from the data provider, not the attribute values.
If you have graduated symbol classification, only the classification
attribute is contained in the features.
To get also the attributes from QgsVectorDataProvider, you need to apply
QgsVectorDataProvider::getNextFeature with a list of all the attribute
indexes you need.
Regards,
Marco
Am Montag, 12. März 2007 17:20 schrieb Peter Ersts:
> Howdy,
>
> I am trying to get a list of attributes from the selected features for a
> layer but am not having much success. Below is my basic approach:
>
> void foo::bar(QgsVectorLayer* layer)
> {
> .......
> QgsFeatureList mySelectedFeatures = layer->selectedFeatures();
> const QgsAtrributeMap& myAttributeMap =
> mySelectedFeatures[0].attributeMap();
> .......
> }
>
> The size of the selected list correct, mySelectedFeatures[x].featureId()
> returns correct featureids, but attributMap(), fields() etc. return
> empty lists. What am I missing here?
>
> I eventually got what I needed by using
> layer->getDataProvider()->getFeatureAtId(......) but I am wondering why
> the other approach does not work.
>
> Any help or explanation would be greatly appreciated.
>
> -pete
More information about the Qgis-developer
mailing list