1

I want to know how to get features from a layer on click event.. using python(m trying to create a plugin).. the below code always show 0 output

layer = iface.activeLayer()
selection = layer.selectedFeatures()
print len(selection)
for feature in selection:
    print feature['NAME']
1
  • Welcome to GIS SE! As a new user be sure to take the Tour. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely.
    – PolyGeo
    Commented Apr 14, 2017 at 5:40

1 Answer 1

2

This works fine for me

layer = iface.activeLayer()

h = layer.selectedFeatures()

for f in h: print f['ID']

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.