Pyqgis: Added raster layers do not show up

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

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



Use raster memory layer from QGIS processing result

Updated March 06, 2019 16:22 PM

Using grass:r.to.vect in PyQGIS correctly?

Updated November 14, 2016 07:38 AM