How to set transparency to multiple raster values with Python
I found this other thread which was helpful How do I set layer transparency in QGIS 2.0 with Python? It seems like there should be a shorter and more efficient way, but I tested this and it works:
print 'Start'
active_layer = qgis.utils.iface.mapCanvas().currentLayer()
raster_transparency = active_layer.renderer().rasterTransparency()
ltr = QgsRasterTransparency.TransparentSingleValuePixel()
ltr2 = QgsRasterTransparency.TransparentSingleValuePixel()
tr_list = []
ltr.min = 0 # Or another value
ltr.max = 0 # Or another value
ltr.percentTransparent = 100 # Or another value
ltr2.min = 8 # Or another value
ltr2.max = 8 # Or another value
ltr2.percentTransparent = 100
tr_list.append(ltr)
tr_list.append(ltr2)
raster_transparency.setTransparentSingleValuePixelList(tr_list)
active_layer.triggerRepaint() # Tried with iface.mapCanvas().refresh(), but it didn't work
print 'Finish'
Is Python a requirement? If I understand what you want, you can do this in the QGIS UI, in the raster layer properties: