Friday, 5 January 2018

qgis - How do I get the feature id after featureAdded signal (PyQGIS)?


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()])

Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...