1

I am created a plugin that creates point features and line features from a SpatiaLite database. The lines must be snapped to a point at least in one end.

Then problem is that the last created point features are not identified by the snap indicator.

They are inside the database, even labels are displayed immediately. I have to close the project to be able to snap on them.

I tried in my code the three following sentences(together) after 'layer.commitChanges()' :

layer.reload()
QgsProject.instance().reloadAllLayers()
layer.setDataSource( layer.source(), layer.name(), layer.providerType() )

But this is not working.

How to I make the snapper recognize the new points?

1 Answer 1

1

I found the answer in this link:

https://github.com/MorriganR/index_updater, the code bit that made the trick is

layer.emitDataChanged()

Nonetheless, I left all the other refreshing statements I had collected:

layer.commitChanges()
layer.reload()
QgsProject.instance().reloadAllLayers()
layer.setDataSource( layer.source(), layer.name(), layer.providerType() )
if self.iface.mapCanvas().isCachingEnabled():
    layer.triggerRepaint()
else:
    self.iface.mapCanvas().refresh()  
layer.emitDataChanged()

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.