Geographic Information Systems Asked on August 5, 2021
I often have to reload layers in the layers panel after doing changes in the DB-Manager (add a column, delete a default value, …). At the moment I use the changeDatasource plugin. Can this also be done using Python?
I've read several answers for this specific question; none of them seems to work. The only effective solution I could find is:
layer.setDataSource( layer.source(), layer.name(), layer.providerType() )
Tested in QGIS v2.14.8.
Correct answer by Germán Carrillo on August 5, 2021
if you have your layer as a variable, simply layer.reload()
You can obtain a list of all layers of the current project from QgsMapLayerRegistry.instance().mapLayers()
If you don’t care about reloading all other layers at the same time, the one-liner
QgsMapLayerRegistry.instance().reloadAllLayers()
does the job, too.
References:
Answered by christoph on August 5, 2021
QgsProject.instance().reloadAllLayers()
worked for me on QGIS 3.10.
Answered by Romário Carvalho Neto on August 5, 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