Pyqgis: Added raster layers do not show up

by jannik schilling   Last Updated July 12, 2019 08:22 AM

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 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



Related Questions


Updated June 06, 2017 13:22 PM

Updated March 06, 2019 16:22 PM

Updated November 14, 2016 07:38 AM

Updated February 27, 2017 21:22 PM

Updated September 20, 2017 15:22 PM