Hello,
<div><br></div><div>I am working on a plugin (I mentioned it on the list earlier, but it isn't relevant to the question I have now). I have the results written to a raster file, and I need to display it. I am using this code:</div>
<div><br></div><div><div>        resultsLayer = qgis.core.QgsRasterLayer(self.query.results_file, QtCore.QFileInfo(self.query.results_file).baseName())</div><div>        qgis.core.QgsMapLayerRegistry.instance().addMapLayer(resultsLayer)</div>
</div><div><br></div><div><br></div><div>which works fine for opening the file, but I would like to fine-tune the display so the user doesn't have to reset the properties (in my test exaple the values are 0 and 1 and the display is essentially all black). I would like to either display the results in pseudocolor directly, or in grayscale with the scale stretched to the min and max extent of the raster.</div>
<div><br></div><div>I tried the psuedocolor with this code:</div><div><br></div><div><div>        resultsLayer.setDrawingStyle(qgis.core.QgsRasterLayer.SingleBandPseudoColor)</div><div>        resultsLayer.setCacheImage(None)</div>
<div>        resultsLayer.triggerRepaint()</div></div><div><br></div><div>which doesn't seem to do anything at all, and I am just guessing, really.</div><div><br></div><div>I found a nice tutorial about how to calculate the min and max extent of a raster and adjust the display here:</div>
<div><br></div><div><a href="http://linfiniti.com/2010/08/a-simple-qgis-python-tutorial/">http://linfiniti.com/2010/08/a-simple-qgis-python-tutorial/</a></div><div><br></div><div>and I tried the following code:</div><div>
<br></div><div><div>        band = resultsLayer.bandNumber(resultsLayer.grayBandName())</div><div>        extentMin = 0.0</div><div>        extentMax = 0.0</div><div>        generateLookupTableFlag = False</div><div>        extentMin, extentMax = resultsLayer.computeMinimumMaximumFromLastExtent(band)</div>
<div>        resultsLayer.setMinimumValue(band, extentMin, generateLookupTableFlag)</div><div>        resultsLayer.setMaximumValue(band, extentMax, generateLookupTableFlag)</div><div>        resultsLayer.setStandardDeviations(0.0)</div>
<div>        resultsLayer.setUserDefinedGrayMinimumMaximum( True )</div><div>        resultsLayer.setCacheImage(None)</div><div>        resultsLayer.triggerRepaint()</div></div><div><br></div><div>but that fails with the following error:</div>
<div><br></div><div>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Traceback (most recent call last):<br>  File "/Users//.qgis/python/plugins/mcelite/MCELiteDialog.py", line 361, in accept<br>
    extentMin, extentMax = resultsLayer.computeMinimumMaximumFromLastExtent(band)<br>TypeError: 'float' object is not iterable<br></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
<br></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">and I don't understand what the float object is, exactly.</p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
<br></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Any help or suggestions much appreciated.</p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
<br></p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Cheers,</p><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
JP</p></div>