is it possible to set a listener that is fired when a feature is edited? What I imagine is this: A geometry is edited (e.g. cut operation) then a listener is fired. This event gives me back the altered geometry. Purpose: A geometry is edited and the current area of the geometry is displayed in a window.
The class QgsVectorLayer provides several listeners (e.g. layerModified). Unfortunately I just get the message that something has been edited, but not the edited feature.
Is there any way to set a listener for a specific feature?
All ideas and suggestions are welcome. (:
Answer
To get information on the changed features use signal committedGeometriesChanges
. This gives you the feature id and new geometry of any changed feature of the layer you connect a handler to.
As an example:
def feedback(layerId, changedGeometries):
for k, v in changedGeometries.items():
# v contains geometry and it's further usage is up to you
print 'id: %d, geometry: %s' % (k, v.exportToWkt())
layer = iface.activeLayer()
layer.committedGeometriesChanges.connect(feedback)
Output on console after some editing is saved:
id: 1, geometry: LineString (47.19158866759342175 24.98144494566650309, ...,
48.26832652730565343 25.72949440609816207)
No comments:
Post a Comment