Hi Bob<div><br></div><div>On Thursday, October 6, 2011, Bob and Deb wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>Hello list,</p>
<p>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.</p></blockquote><div><br></div><div>
This way you can access current list of transparency values:</div><div><br></div><div>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> rt=l.rasterTransparency()</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> lst = rt.transparentSingleValuePixelList()</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> for item in lst: print item.pixelValue, item.percentTransparent</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">... </p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">-9999.0 100.0</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">0.0 50.0</p></div><div><br></div><div>To set a list with just one value:</div><div><br></div><div>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> x = QgsRasterTransparency.TransparentSingleValuePixel()</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> x.pixelValue = 123</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> x.transparencyPercent = 50</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">>>> rt.setTransparentSingleValuePixelList( [ x ] )</p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">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.</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">Martin</p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<br></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "></p></div></div>