I have been struggling with setting the
colorshadingalgorithm for a raster layer in QGIS with no success for the past few days. The QGIS cookbook seems to be pretty outdated.
The code that I am using is:
QgsApplication.setPrefixPath("/usr", True) QgsApplication.initQgis() app = QgsApplication(, True) plotdir = r"/home/qgis_prac/" inShp = r"/home/qgis_prac/shps/Peru_Boundary.shp" uri = r"/home/qgis_prac/tiffs/Peru_DEM.tif" layer = QgsRasterLayer(uri, "Peru_DEM") QgsMapLayerRegistry.instance().addMapLayer(layer) layer.setDrawingStyle('SingleBandPseudoColor') # main thing goes wrong here, I think layer.ColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader) # seems to do nothng. Also the setColorShadingAlgorithm is deprecated if hasattr(layer, "setCacheImage"): layer.setCacheImage(None) layer.triggerRepaint()
The code goes on....
My problem is that when the script runs, it gives me an empty map with no entries in the legend. If I use the grayband shader then it works, also for the
PalettedColor (but some cells are assigned colors).
What I need is some replacement or work around setting the