I am trying to automatically style a singlebandgray raster image with one
of the singlebandpseudocolor color ramps. When I run this code in the QGIS
Python console the raster image disappears. If I look at the image
"Properties" everything seems to be set correctly and it does appear when
Apply or OK buttons are clicked on. I must be missing something.
layer = iface.activeLayer()
style = QgsStyle.defaultStyle()
# Get the Reds default colorramp
ramp = style.colorRamp('Reds')
color_ramp = QgsColorRampShader()
color_ramp.setSourceColorRamp(ramp)
color_ramp.setColorRampType(QgsColorRampShader.Interpolated)
raster_shader = QgsRasterShader()
raster_shader.setRasterShaderFunction(color_ramp)
# Create a new single band pseudocolor renderer
renderer = QgsSingleBandPseudoColorRenderer(layer.dataProvider(),
layer.type(), raster_shader)
layer.setRenderer(renderer)
layer.triggerRepaint()
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user