[Qgis-user] Raster layer display control from Plugin
JP Glutting
jpglutting at gmail.com
Thu Sep 2 18:04:52 PDT 2010
Hello,
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:
resultsLayer = qgis.core.QgsRasterLayer(self.query.results_file,
QtCore.QFileInfo(self.query.results_file).baseName())
qgis.core.QgsMapLayerRegistry.instance().addMapLayer(resultsLayer)
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.
I tried the psuedocolor with this code:
resultsLayer.setDrawingStyle(qgis.core.QgsRasterLayer.SingleBandPseudoColor)
resultsLayer.setCacheImage(None)
resultsLayer.triggerRepaint()
which doesn't seem to do anything at all, and I am just guessing, really.
I found a nice tutorial about how to calculate the min and max extent of a
raster and adjust the display here:
http://linfiniti.com/2010/08/a-simple-qgis-python-tutorial/
and I tried the following code:
band = resultsLayer.bandNumber(resultsLayer.grayBandName())
extentMin = 0.0
extentMax = 0.0
generateLookupTableFlag = False
extentMin, extentMax =
resultsLayer.computeMinimumMaximumFromLastExtent(band)
resultsLayer.setMinimumValue(band, extentMin,
generateLookupTableFlag)
resultsLayer.setMaximumValue(band, extentMax,
generateLookupTableFlag)
resultsLayer.setStandardDeviations(0.0)
resultsLayer.setUserDefinedGrayMinimumMaximum( True )
resultsLayer.setCacheImage(None)
resultsLayer.triggerRepaint()
but that fails with the following error:
Traceback (most recent call last):
File "/Users//.qgis/python/plugins/mcelite/MCELiteDialog.py", line 361, in
accept
extentMin, extentMax =
resultsLayer.computeMinimumMaximumFromLastExtent(band)
TypeError: 'float' object is not iterable
and I don't understand what the float object is, exactly.
Any help or suggestions much appreciated.
Cheers,
JP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20100903/1765d7a8/attachment.html>
More information about the Qgis-user
mailing list