[Qgis-developer] Adding Attributes to Vector Layor (QGIS 0.9.1)

Martin Dobias wonder.sk at gmail.com
Tue Feb 26 13:38:02 EST 2008


Hi,

in case you're still stuck, here's my explanation - Tim's tutorials
have been done for 0.8.x series, however in meanwhile we've been doing
some modifications to vector layers handling. To get it working, you
must first call select() function of the provider. You can pass it
some arguments that will tell it what data you need - whether to fetch
attributes, whether to fetch geometries etc. Since by default
attributes are not being fetched, this should be the source of your
problems.

Adding this before the while cycle should help you (it will return you
all attributes for every feature):

allAttrs = mypProvider->allAttributesList()
mypProvider->select(allAttrs)

Regards
Martin

On Mon, Feb 18, 2008 at 1:14 AM, nathan leverington <nleverin at gmail.com> wrote:
> Hi all,
>
> Im new qgis and gis in general so sorry for the newbie question.
>
> im currently having a problem with adding attributes to the vector layor.
>
> Im using qgis 0.9.1 development libraries and creating my own application
> using Open Suse 10.3.  I was following Tim Sutton tutorial 6 to implement
> this but have noticed that QgsFeatureAttribute class has been removed from
> the 0.9.1 release.
>
> I have changed the the tutorial code:
>  while ((mypFeature = mypProvider->getNextFeature(true)))
>  {
>  //get the attributes of this feature
>  const std::vector < QgsFeatureAttribute >& myAttributes =
> mypFeature->attributeMap();
>
>
>  for (int i = 0; i < myAttributes.size(); i++)
>
>
> with the following:
>
>     //now iterate through each feature
>     while (mypProvider->getNextFeature(mypFeature))
>     {
>       //get the attributes of this feature
>       // const std::vector < QgsFeatureAttribute >& myAttributes =
> mypFeature->attributeMap();
>        const QgsAttributeMap& myAttributes = mypFeature.attributeMap();
>
>       if( myAttributes.isEmpty() ) cout << "attribute map is empty " <<
> endl;
>
>
> Iv tried replacing the  QgsFeatureAttribute with the QgsAttributeMap, but
> when calling the attributeMap() function i do not seem to be pulling in the
> attribute data.
>
> Is this a problem with the shapefile datastore.  (i.e. i am using the same
> source shapefile data that was used for Tim's tutorial 6)
>
> thanks in advance,
>
> nlev.
>
>
> _______________________________________________
>  Qgis-developer mailing list
>  Qgis-developer at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>


More information about the Qgis-developer mailing list