Tuesday, 24 May 2016

editing - Getting number of new features to be stored in layers using PyQGIS?


In PyQGIS, how can I get the number of features that have been created in a given layer and that are pending to be saved in the layer when "Toggle editing" or "Saving layer edits"?



Answer



Say that you have a vector layer referenced:


lyr = iface.activeLayer()

At this point, I assume you start an edit session and digitize some features.


Now you can use the QgsVectorLayerEditBuffer class, in this way:


if lyr.editBuffer():

print len( lyr.editBuffer().addedFeatures() ), "features to add!"

addedFeatures gives you a dictionary of new features that are pending. As you're interested in the count, you can use len().


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...