I am trying to load an .ecw file with pyqgis on a pc. Usin version 2.14 of QGIS. I tried the code i could find in the cookbook about loading and rendering raster from it I interpred this code:
from qgis.core import QgsRasterLayer
import os
os.chdir(r'C:\some\path')
file = 'FooBar.ecw'
fileInfo = QFileInfo(file)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(file, baseName)
if not rlayer.isValid():
print "Layer failed to load again!"
else:
print rlayer.renderer()
print rlayer.renderer().type()
if hasattr(rlayer, "setCacheImage"):
rlayer.setCacheImage(None)
rlayer.triggerRepaint()
I will get a dialog window where I get to define the projection for the raster. But th file will not draw. The file is fully functionall to load normally. How can I make the raster draw with pyqgis?
qgis.utils.iface.addRasterLayer("/path/to/raster", "any_name")
to load the raster to the map registry. I think what you are doing is just accessing the raster but not loading it.