I have a downloaded raster file, singlebandgray, and want to redefine it's maximum value to a higher integer value. Via the QGIS desktop it works smoothly by hand via the Properties. Via Python I was not able to figure it out. I tried something like this (some snippets that I found somewhere)
fcn = QgsColorRampShader() fcn.setMaximumValue(66) shader = QgsRasterShader()shader.setRasterShaderFunction(fcn) renderer = QgsSingleBandGrayRenderer(rasterlayer.dataProvider(), 1, shader) rasterlayer.setRenderer(renderer)
The raster file is saved as "rasterlayer". Its minimum value is 0. The maximum value should be 66 instead of a lower integer. Everything else should stay equal.
I should add that I am not looking for a solution which loads the style with an external .qml file. I tried that and it works fine. But it is not my desired solution.