0

I am catching the selectionChanged signal and passing the selected layer to the registered method. Once here, I want to know the features that were selected. I do this with a call to layer.selectedFeatures().

The return type from this call is a QgsFeatureList. As a test, I'm trying to print the values of the features in the QgsFeatureList that was selected, or just display them in a simple way. I find that neither QgsFeatureList nor QgsFeature has any functions returning a QString.

How can I print the values of the features that were selected?

1 Answer 1

0

Here is an example from the Python Console:

layer = iface.activeLayer()
features = layer.selectedFeatures()
for feature in features:
    print feature['NAME']

Vancouver
Prince Rupert
Juneau
San Jose
Salt Lake City
Portland
3
  • Is there a way to extract all values from each feature without having to index them by name?
    – user28233
    Commented Apr 24, 2014 at 6:53
  • I could iterate using int indexes, but I was thinking more along the lines of one whole feature at a time.
    – user28233
    Commented Apr 24, 2014 at 7:03
  • Using the QgsFeature.attributes() function is what I was looking for. It returns all the attributes of a feature.
    – user28233
    Commented Apr 24, 2014 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.