2

I'm trying to edit vector layer using Python console and have couple of questions. Why this approach doesn't work and I have to use canvas.refresh? If I will use this code not in python console but in script file should I also use canvas.refresh?

# This approach doesn't work
layer = qgis.utils.iface.activeLayer()
layer.startEditing()
layer.moveVertex(7402946,6186167,0,0)

# This one works fine
canvas = qgis.utils.iface.mapCanvas()
layer = qgis.utils.iface.activeLayer()
layer.startEditing()
canvas.refresh()
layer.moveVertex(7402946,6186167,0,0)

What is the right way to perform such operation? I've found that I can make the same things using QgsVectorLayerEditUtils:

layer.startEditing()
eu = QgsVectorLayerEditUtils(layer)
canvas.refresh()
eu.moveVertex(7402946,6186167,0,0)   
  • What do you mean by # This approach doesn't work? – Nathan W Nov 26 '13 at 3:55
  • I mean that moveVertex returns False and there are no visible changes after canvas refreshing. – drnextgis Nov 26 '13 at 4:04
  • It's because the vertex markers are not draw until a canvas refresh which is what moveVertex is doing. The correct way to move a node is to edit the geometry. – Nathan W Nov 26 '13 at 4:20
  • @Nathan W, sounds like an answer! – artwork21 Dec 21 '16 at 19:47

Your Answer

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

Browse other questions tagged or ask your own question.