I am using QGIS Chugiak 2.4.0, and I have some code in which I want to:
- Add raster layer to map canvas
- Look for the minimum and maximum raster value
- Apply singleband pseudocolor render type for the min max values
- Use a nice color map (e.g. RdYlBl)
- Update the map canvas/legend with these settings
I found some code in the PyGis cookbook as shown below:
layer = QgsRasterLayer(file, layername) rastermin = ? rastermax = ? layer.setDrawingStyle("SingleBandPseudoColor") layer.setColorShadingAlgorithm(QgsRasterLayer.ColorRampShader) lst = [ QgsColorRampShader.ColorRampItem(rastermin, QColor(0,255,0)), QgsColorRampShader.ColorRampItem(rastermax, QColor(255,255,0)) ] fcn = rlayer.rasterShader().rasterShaderFunction() fcn.setColorRampType(QgsColorRampShader.INTERPOLATED) fcn.setColorRampItemList(lst)
First of all, I don't know how to retrieve the minimum and maximum values of the raster layer.
Secondly, it seems that
setColorShadingAlgorithm does not work in QGIS Chugiak 2.4.0.
Thirdly, instead of using the
QColor(0,255,0) I'd like to use one of the nice existing colormaps in QGIS, e.g.RdYlBl.
Does anyone have any clue how to solve this?
Best Regards, Wilco