[Qgis-developer] Help with QgsVectorLayer

Peter Ersts ersts at amnh.org
Mon Mar 12 12:20:29 EDT 2007


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

-- 
====================================
Peter J. Ersts, Project Specialist
American Museum of Natural History
Center for Biodiversity and Conservation
Central Park West at 79th Street
New York, New York 10024
Tel: (212)-496-3488 or (212)-769-5742
Fax: (212)-313-7295 or (212)-769-5292
Web: http://cbc.amnh.org

Visit the Indo-South Atlantic Consortium on Humpback Whales 
Web:  http://www.isach.org




More information about the Qgis-developer mailing list