[Qgis-developer] Custom raster transparency in Python?

Martin Dobias wonder.sk at gmail.com
Fri Oct 7 08:36:30 EDT 2011


Hi Bob

On Thursday, October 6, 2011, Bob and Deb wrote:

> Hello list,
>
> Is there a way set the transparancy based on certain raster values?  I know
> that it can be done by setting the rasters Custom transparency options, but
> I would like to do it in Python.
>

This way you can access current list of transparency values:

>>> rt=l.rasterTransparency()

>>> lst = rt.transparentSingleValuePixelList()

>>> for item in lst: print item.pixelValue, item.percentTransparent

...

-9999.0 100.0

0.0 50.0

To set a list with just one value:

>>> x = QgsRasterTransparency.TransparentSingleValuePixel()

>>> x.pixelValue = 123

>>> x.transparencyPercent = 50

>>> rt.setTransparentSingleValuePixelList( [ x ] )


The above examples suppose that you use single band raster. In case of RGB
image the steps are similar, just instead of "SingleValue" methods you would
use "ThreeValue" methods and instead of "pixelValue" attribute there are
"red", "green", "blue" attributes.


Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20111007/0b8d79e3/attachment.html


More information about the Qgis-developer mailing list