TransWikia.com

Added raster layers with PyQGIS do not show up

Geographic Information Systems Asked by jannik schilling on February 9, 2021

I have a list ("datList") with names of raster layers which I want to add. When I add raster layers in the Python Console everything works fine:

for da in datListe:
   layerDir = "C:/[path]/" + da
   iface.addRasterLayer(layerDir,da)

When I do the same in a processing script with…

for da in datListe:
   layerDir = "C:/[path]/" + da
   rlayer = QgsRasterLayer(layerDir,da)
   QgsProject.instance().addMapLayer(rlayer) 

the layers are not added to my map. However, they seem to be in the project as

QgsProject.instance().mapLayers()

(typed in the Python Console) prints a list with the desired layers

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