[Qgis-developer] Help with QgsVectorLayer

Tim Sutton tim at linfiniti.com
Mon Mar 12 16:33:46 EDT 2007


Hi

I ha(d/ve) a tutorial on blog.qgis.org that explains at least some of
this but it seems to be missing from the blog. Ill post the link when
we manage to revive it.

Regards

Tim

2007/3/12, Marco Hugentobler <marco.hugentobler at karto.baug.ethz.ch>:
> 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
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.qgis.org
> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>


-- 
-- 
Tim Sutton

Visit http://qgis.org for a great Open Source GIS
Home Page: http://linfiniti.com
Skype: timlinux
MSN: tim_bdworld at msn.com
Yahoo: tim_bdworld at yahoo.com
Jabber: timlinux
Irc: timlinux on #qgis at freenode.net



More information about the Qgis-developer mailing list