I'm working on a Dockwidget with PyQgis.

I made an insert into an Oracle DB and a Spatialite DB and I would like to see the new insert (it's a point).

enter image description here

The Layer where the new point is add is URB_A_ADPT. I'm sure the point is create because I see it in my DB and attribute table. For now, when I zoom and dezoom the point appears but I would like to see it directly.

I tried to simply add

self.refresh = self.canvas.refreshAllLayers()

but it don't seems to be enough to refresh my Oracle layer.

I also tried

if iface.mapCanvas().isCachingEnabled():

from the idea of @andreas-müller but once again I don't see anything.

And my last idee was to set zoom and then directly dezoom

active_layer = iface.activeLayer()

but it don't work.

layer = iface.activeLayer()

if iface.mapCanvas().isCachingEnabled():

This one is from the docs, and as mentioned there, it should refresh the query from your database, too. I added a layer-access by iface.activeLayer(), but it could be any method to get a reference to the layer which needs to be refreshed.

  • Finally, I was able to use the layer.triggerRepaint() but I didn't know how to specify the layer, I needed : layer = QgsProject.instance().mapLayersByName("layer_name")[0] layer.triggerRepaint() , but I don't use the Oracle DB for the visual anymore, Spatialite goes faster. Also I didn't need isCachingEnabled() and iface.mapCanvas().refresh(). If you edit your answer with the definition of the layer (and maybe without "if else" but not sure (?) ) I will accept it ! – Svhooren Dec 18 '19 at 15:00
  • Also, should I edit my question only for Spatialite because I didn't try to use Oracle again ? ( and Thank you for the help by the way !) – Svhooren Dec 18 '19 at 15:06
  • this could be usefull, but the problem with the Oracle-DB may also be important. Because Oracle is really complex, it would be an idea to ask that question in another stackexchange site. – Andreas Müller Dec 18 '19 at 16:02

For Spatialite:

It works when I specify the layer and set auto refresh:

layer = QgsProject.instance().mapLayersByName("my_layer_name")[0] 

For Oracle it takes too much time for the visual part, so I interact with spatialite in QGis, but I make my SQL statements on the two DB in parallel.

  • Auto Refresh was a temporary solution, but it takes a lot of memory, I don't recommend it with big database (such as mine) ! – Svhooren Dec 18 '19 at 14:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.