5

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?

  • The method 'setNoDataValue' is in QgsRasterDataProvider. – xunilk Mar 8 '17 at 16:54
5

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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