TransWikia.com

Enabling snapping on features created with PyQGIS

Geographic Information Systems Asked by Vianney Bajart on May 22, 2021

I have implemented a custom digitizing tool derivated from QgsMapToolDigitizeFeature class.

Here is the code written to save the feature into the layer:

layer.dataProvider().addFeatures([feature])
layer.commitChanges()

layer.triggerRepaint()
self.canvas().refresh()
  1. I use the standard QGIS tool to create a new feature A. The feature A is properly added to the layer.
  2. I use my custom tool to create a new feature B. The feature B is properly added to the layer.
  3. Then, I use the QGIS standard tool again. Snapping works on A vertices but not on B.
  4. If I save the project, close it and open it again, snapping works as expected on all the features.

How to make the snapping work on newly created features?

Any ideas?

One Answer

Just replacing:

layer.dataProvider().addFeatures([feature])

with:

layer.addFeature(feature)

solved my problem. Snapping works as expected now.

Answered by Vianney Bajart on May 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP