<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.17063" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial color=#0000ff><SPAN class=102273116-04092010>Hi 
JP,</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN class=102273116-04092010>I would 
suggest asking your question on the Qgis-developer list instead of this 
one.</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN class=102273116-04092010>Below is 
what I've done to display a custom colormap on a raster. Could it be adapted to 
your problem?</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010>     <FONT color=#008000># Display 
the raster with the selected colour table:<BR>     
#<BR>     # - tell the layer to use a QgsColorRampShader 
function<BR></FONT>     theLayer.setColorShadingAlgorithm( 
QgsRasterLayer.ColorRampShader )<BR>     <FONT 
color=#008000># - get a pointer to the raster shader function 
(QgsColorRampShader)<BR></FONT>     myColorRampShader = 
theLayer.rasterShader().rasterShaderFunction()<BR>     <FONT 
color=#008000># - set parameters for the QgsColorRampShader 
function</FONT><BR>     myColorRampShader.setColorRampType( 
QgsColorRampShader.DISCRETE )<BR>     
myColorRampShader.setColorRampItemList( theTBL )<BR>     
theLayer.setDrawingStyle( QgsRasterLayer.SingleBandPseudoColor 
)<BR>    <FONT color=#008000> # - refresh map & 
legend<BR></FONT>     if hasattr(theLayer, "setCacheImage"): 
</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010>         
theLayer.setCacheImage( None )<BR>     
theLayer.triggerRepaint()<BR>     
self.iface.legendInterface().refreshLayerSymbology( theLayer 
)<BR>    <FONT color=#008000> # - tell QGIS that it needs to 
ask user to save changes<BR></FONT>     
self.iface.mapCanvas().setDirty( True )<BR></DIV></SPAN></FONT>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010>Cheers,</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010>Benoit</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff><SPAN 
class=102273116-04092010> </DIV></SPAN></FONT>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> 
  qgis-user-bounces@lists.osgeo.org 
  [mailto:qgis-user-bounces@lists.osgeo.org]<B>On Behalf Of </B>JP 
  Glutting<BR><B>Sent:</B> Saturday, 04 September 2010 17:47<BR><B>To:</B> 
  Qgis-user@lists.osgeo.org<BR><B>Subject:</B> [Qgis-user] Re: Raster layer 
  display control from Plugin<BR><BR></FONT></DIV>No takers? No hints? I have 
  been looking all over the place, and I am stuck. If it is something absurdly 
  simple, just point me in the right direction.
  <DIV><BR></DIV>
  <DIV>Any ideas?</DIV>
  <DIV><BR></DIV>
  <DIV>Thanks,</DIV>
  <DIV>JP<BR><BR>
  <DIV class=gmail_quote>On Fri, Sep 3, 2010 at 7:50 AM, JP Glutting <SPAN 
  dir=ltr><<A 
  href="mailto:jpglutting@gmail.com">jpglutting@gmail.com</A>></SPAN> 
  wrote:<BR>
  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Although 
    here (<A href="http://blog.qgis.org/node/94" 
    target=_blank>http://blog.qgis.org/node/94</A>) it seems to indicate that 
    SingleBandPseudoColor is a constant:
    <DIV><BR></DIV>
    <DIV><SPAN 
    style="FONT-SIZE: 12px; LINE-HEIGHT: 20px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BORDER-COLLAPSE: collapse"><PRE style="BORDER-RIGHT: rgb(221,221,221) 1px solid; PADDING-RIGHT: 1.5em; BORDER-TOP: rgb(221,221,221) 1px solid; PADDING-LEFT: 1.5em; FONT-SIZE: 12px; PADDING-BOTTOM: 0.75em; BORDER-LEFT: rgb(221,221,221) 1px solid; PADDING-TOP: 0.75em; BORDER-BOTTOM: rgb(221,221,221) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)">mypLayer->setColorRampingType(QgsRasterLayer::BLUE_GREEN_RED);
  mypLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR);
  std::deque myLayerSet;</PRE></SPAN>
    <DIV>which is what I was thinking in the first place, and here ( <A 
    href="http://doc.qgis.org/stable/classQgsRasterLayer.html#36796f1a303dac9848ba3dce3e5527dc7b7c9814c053986846b579119d2e5be9" 
    target=_blank>http://doc.qgis.org/stable/classQgsRasterLayer.html#36796f1a303dac9848ba3dce3e5527dc7b7c9814c053986846b579119d2e5be9</A> ) 
    DrawingStyle is described as an enumerator, which seems coherent. I am not 
    sure how to do this from Python.</DIV>
    <DIV><BR></DIV>
    <DIV>Cheers,</DIV>
    <DIV>JP</DIV>
    <DIV>
    <DIV></DIV>
    <DIV class=h5><BR>
    <DIV class=gmail_quote>On Fri, Sep 3, 2010 at 7:43 AM, JP Glutting <SPAN 
    dir=ltr><<A href="mailto:jpglutting@gmail.com" 
    target=_blank>jpglutting@gmail.com</A>></SPAN> wrote:<BR>
    <BLOCKQUOTE class=gmail_quote 
    style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
      <DIV>Actually, I am not even sure that first part is the way to do it. I 
      tried this:</DIV>
      <DIV><BR></DIV>
      <DIV>
      <DIV>       
       resultsLayer.setDrawingStyle(QtCore.QString('SingleBandPseudoColor'))</DIV>
      <DIV>
      <DIV>       
       resultsLayer.setCacheImage(None)</DIV>
      <DIV>       
       resultsLayer.triggerRepaint()</DIV></DIV></DIV>
      <DIV><BR></DIV>
      <DIV>(passing the 'SingleBandPseudoColor' style as a string) and it makes 
      the raster invisible. It still shows up black in the Layers Panel, but it 
      doesn't show in the main window until you change the properties manually 
      (and it is Grayscale when you do). It feels like I am pretty close, but I 
      am not sure how to interpret this code from the QGIS documentation:</DIV>
      <DIV><BR></DIV>
      <DIV><SPAN 
      style="FONT-SIZE: 13px; FONT-FAMILY: monospace, fixed">myRasterLayer-><A 
      style="FONT-WEIGHT: normal; COLOR: rgb(0,0,255); TEXT-DECORATION: none" 
      href="http://classQgsRasterLayer.html#3a923f732bedd87d0b920c5552215434" 
      target=_blank>setDrawingStyle</A>(<A 
      style="FONT-WEIGHT: normal; COLOR: rgb(0,0,255); TEXT-DECORATION: none" 
      href="http://classQgsRasterLayer.html#36796f1a303dac9848ba3dce3e5527dc7b7c9814c053986846b579119d2e5be9" 
      target=_blank>QgsRasterLayer::SingleBandPseudoColor</A>);</SPAN></DIV>
      <DIV><BR></DIV>
      <DIV><SPAN 
      style="FONT-SIZE: 13px; FONT-FAMILY: monospace, fixed"></SPAN>(I never 
      learned more than the basics of C++, and that was a long time ago). The 
      source code seems to indicate that the format needs to be passed as a 
      string (of course, when the layer is generated):</DIV>
      <DIV><BR></DIV><SPAN 
      style="FONT-SIZE: 11px; FONT-FAMILY: monospace, fixed"><PRE style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 6px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 6px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; MARGIN: 4px 8px 4px 2px; BORDER-LEFT: rgb(204,204,204) 1px solid; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; FONT-FAMILY: monospace, fixed; BACKGROUND-COLOR: rgb(245,245,245)"><BR>00204     <A style="FONT-WEIGHT: normal; COLOR: rgb(0,0,255); TEXT-DECORATION: none" href="http://classQgsRasterLayer.html" target=_blank>QgsRasterLayer</A>( <SPAN style="COLOR: rgb(96,64,32)">int</SPAN> dummy,
<A style="COLOR: rgb(26,65,168)" name=12ad6257a37c3c34_12ad61ec7902b935_l00205></A>00205                     <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QString & baseName = QString(),
<A style="COLOR: rgb(26,65,168)" name=12ad6257a37c3c34_12ad61ec7902b935_l00206></A>00206                     <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QString & path = QString(),
<A style="COLOR: rgb(26,65,168)" name=12ad6257a37c3c34_12ad61ec7902b935_l00207></A>00207                     <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QString & providerLib = QString(),
<A style="COLOR: rgb(26,65,168)" name=12ad6257a37c3c34_12ad61ec7902b935_l00208></A>00208                     <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QStringList & layers = QStringList(),
<A style="COLOR: rgb(26,65,168)" name=12ad6257a37c3c34_12ad61ec7902b935_l00209></A>00209                     <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QStringList & styles = QStringList(),
<A style="COLOR: rgb(26,65,168)" name=12ad6257a37c3c34_12ad61ec7902b935_l00210></A>00210                     <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QString & format = QString(), </PRE></SPAN>
      <DIV><SPAN style="FONT-SIZE: 13px; FONT-FAMILY: monospace, fixed">00211 
      <SPAN style="COLOR: rgb(0,128,0)">const</SPAN> QString & crs = 
      QString() );</SPAN></DIV>
      <DIV><BR></DIV>
      <DIV><SPAN 
      style="FONT-SIZE: 13px; FONT-FAMILY: monospace, fixed"></SPAN>Thanks,</DIV>
      <DIV>JP </DIV>
      <DIV>
      <DIV></DIV>
      <DIV><BR>
      <DIV class=gmail_quote>On Fri, Sep 3, 2010 at 3:04 AM, JP Glutting <SPAN 
      dir=ltr><<A href="mailto:jpglutting@gmail.com" 
      target=_blank>jpglutting@gmail.com</A>></SPAN> wrote:<BR>
      <BLOCKQUOTE class=gmail_quote 
      style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">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/" 
        target=_blank>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: 0px; 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: 0px; TEXT-INDENT: 0px"><BR></P>
        <P style="MARGIN: 0px; TEXT-INDENT: 0px">and I don't understand what the 
        float object is, exactly.</P>
        <P style="MARGIN: 0px; TEXT-INDENT: 0px"><BR></P>
        <P style="MARGIN: 0px; TEXT-INDENT: 0px">Any help or suggestions much 
        appreciated.</P>
        <P style="MARGIN: 0px; TEXT-INDENT: 0px"><BR></P>
        <P style="MARGIN: 0px; TEXT-INDENT: 0px">Cheers,</P>
        <P 
      style="MARGIN: 0px; TEXT-INDENT: 0px">JP</P></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></DIV></BLOCKQUOTE></DIV><BR></DIV></BLOCKQUOTE></BODY></HTML>