2

I'm trying to make an edit form in QGIS (Python code) ,and i want after feature drawing to get the id, and the feature to be selected.
Do you have any ideas to do that?

Tried so far:

self.iface.activeLayer().featureAdded.connect(self.myfonction)

def myfonction(self): 
    for feat in self.iface.activeLayer().getFeatures():
        self.iface.activeLayer().setSelectedFeatures([feat.id()]) 
  • Can you show us what you have so far? – ArMoraer Feb 17 '16 at 15:30
  • self.iface.activeLayer().featureAdded.connect(self.myfonction) def myfonction(self): for feat in self.iface.activeLayer().getFeatures(): self.iface.activeLayer().setSelectedFeatures([feat.id()]) – G3orge Feb 17 '16 at 15:36
  • I added your code into your question, for readability purposes. – ArMoraer Feb 17 '16 at 16:00
1

From the doc, it seems that featureAdded sends the feature id as argument. You can replace def myfonction(self) with def myfonction(self, fId) and use fId in your function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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