6

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

1 Answer 1

7

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 feat_id, geom in changedGeometries.items():
        print(f'id: {feat_id}, geometry: {geom.asWkt()}')

layer = iface.activeLayer()
layer.committedGeometriesChanges.connect(feedback)

Output on the Console after some editing is saved:

id: 1, geometry: LineString (47.19158866759342175 24.98144494566650309, ...,
     48.26832652730565343 25.72949440609816207)

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.