Geographic Information Systems Asked by Roo on June 2, 2021
I have the same problem as Making QGIS layer update from changed data source.
However, I cannot get the solution proposed by Matthias Kuhn in a comment on an answer to that question to work.
I am using QGIS 3.4, I have loaded a .geojson file as a vector layer and am trying to refresh it without removing and re-adding. The map refreshes when I move it but the attribute table is not re-loaded.
I may not have understood how to use the reload function so here are my steps, I am using the Python Console.
mc = iface.mapCanvas()
layer = mc.currentLayer()
layer.name()
'radarOutGJTemp' #--- Correct
# Tried the following with errors attached
layer.dataProvider().reload()
AttributeError: 'QgsVectorDataProvider' object has no attribute 'reload'
layer.dataProvider.reload('radarOutGJTemp')
AttributeError: 'builtin_function_or_method' object has no attribute 'reload'
layer.dataProvider.reload(radarOutGJTemp)
AttributeError: 'builtin_function_or_method' object has no attribute 'reload'
I can see the function reload appear in a window as I type. I did try to import reload just in case, that failed but again I could see it appear in the window as I typed.
import reload
ModuleNotFoundError: No module named 'reload'
With help from @BenW, the following lines refresh my map when I run them in the QGIS Python console using QGIS v3.4.
mc = iface.mapCanvas()
layer = mc.currentLayer()
layer.dataProvider().reloadData()
layer.triggerRepaint()
The final step is explained in the following post.
Does mapCanvas().refresh() not work in QGIS 2.6?
Answered by Roo on June 2, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP