2

How do I set the min/max values of my Singleband pseudocolor layer style using PyQGIS?

The new values are set, but the layer style does not change.

If I set them manually the update is instant. But if I set max to 0.1 using pyqgis the value change but the layer looks the same. I have to erase and type 0.1 for it to update.

layer = QgsProject.instance().mapLayersByName("NDVItest2")[0]
newrend = layer.renderer().clone()
newrend.setClassificationMin(0)
newrend.setClassificationMax(0.1)
layer.setRenderer(newrend)
iface.mapCanvas().refresh()
iface.mapCanvas().refreshAllLayers() 

enter image description here

0

1 Answer 1

3

Okay, after a bit of trying it out: You are likely missing the equivalent of hitting the "Classify" button in the GUI, as well as triggerRepaint.

layer = QgsProject.instance().mapLayersByName("NDVItest2")[0]
newrend = layer.renderer().clone()
newrend.setClassificationMin(0)
newrend.setClassificationMax(0.1)
layer.setRenderer(newrend)
newrend.shader().rasterShaderFunction().classifyColorRamp()
layer.triggerRepaint()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.