7

I need a raster layer transparency configured like this:

enter image description here

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?

1
  • 1
    The method 'setNoDataValue' is in QgsRasterDataProvider.
    – xunilk
    Commented Mar 8, 2017 at 16:54

1 Answer 1

7

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()
0

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.