[Qgis-developer] Using QgsAttributeMap to get feature attribute value

Matthew Denno mgdenno at gmail.com
Fri Jul 17 23:45:54 EDT 2009


Hi,

I am having a problem that I am hoping someone can help me with.  I have a
piece of code that iterates through a feature class and pulls out the x and
y coordinates from the geometry.  The z values are stored in the attribute
table and I would also like to pull that value for each feature.  I have
looked at Tutorial 6, but it looks like the classes have changed since it
was written, I think.  I can see that feature.attributeMap() returns a
dictionary of Key-Value pairs (I think) but I can't figure out how to get
the "Elevation" field attribute value from that.  Here is the piece of code:

 while (mypVectorLayer->nextFeature(currentFeature))

{

//get geometry of the feature

QgsGeometry* currentGeometry = currentFeature.geometry();

QgsPoint currentPoint = currentGeometry->asPoint();


 //get the attributes of this feature

const QgsAttributeMap& myAttributes = currentFeature.attributeMap();


 //get the value from the "Elevation" field

double zval = //value from field



//add point coordinates to point and add point to dt

 Point pt = Point(currentPoint.x(), currentPoint.y(), zval);

dt.insert(pt);

//delete currentFeature;

}


Thanks,


Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090717/3325a524/attachment.html


More information about the Qgis-developer mailing list