I need a raster layer transparency configured like this:
Since I load the layer with PyQgis, the parameters should be set programmatically. For global transparency and transparency band I found that it works via myrasterlayer.renderer().setOpacity()
and myrasterlayer.renderer().setAlphaBand(0)
, but I did not find a method to set the additional no data value to 0
: http://qgis.org/api/classQgsRasterRenderer.html
How to set this value with PyQgis?
Answer
The method 'setNoDataValue' is in QgsRasterDataProvider. You can use next code to try it out. It worked for me.
layer = iface.activeLayer()
provider = layer.dataProvider()
provider.setNoDataValue(1, 0) #first one is referred to band number
layer.triggerRepaint()
No comments:
Post a Comment