Martin,

Solved GDAL 1.7 access on OSGeo4W thanks to Duarte and started again to test
thanks to the latest release (r14026) but still unable to produce the
colormap!

Here is the code I'm using:

   # tell the layer to use a QgsColorRampShader function
   theLayer.setColorShadingAlgorithm( QgsRasterLayer.ColorRampShader )
   theLayer.rasterShader().setRasterShaderFunction( QgsColorRampShader() )

   # get the raster shader function: should be a QgsColorRampShader
   myColorRampShader = theLayer.rasterShader().rasterShaderFunction()

   # set parameter for the QgsColorRampShader function
   myColorRampShader.setColorRampItemList( theTBL )
   myColorRampShader.setMaximumColorCacheSize( nColo )
   myColorRampShader.setColorRampType( myColorRampShader.DISCRETE )

   # feed my custom QgsColorRampShader back to the raster
   theLayer.setRasterShaderFunction( myColorRampShader )

It does not produce an error but raster does not change to the given
colormap. Furthermore on quitting QGIS it bombs out (access violation, from
debug).
Do you have an idea of what I'm doing wrong? I've tried to base the code on
the 'Apply' C++ code on the qgsrasterlayerproperties.cpp file.

The original code below produced an "Access violation - no RTTI data" error
without doing anything. Do you know the meaning of that error? Is there a
wiki of the meaning of all errors in QGIS?

Thanks all for your help,
Benoit


> -----Original Message-----
> From: Martin Dobias [mailto:wonder...@gmail.com]
> Sent: Saturday, 07 August 2010 17:10
> To: ben...@exigesa.com
> Cc: qgis-developer@lists.osgeo.org
> Subject: Re: [Qgis-developer] How to load a colour table on a raster,
> programmatically (in python)?
>
>
> On Fri, Aug 6, 2010 at 2:43 PM, Benoit de Cabissole
> <ben...@exigesa.com> wrote:
> > I've tried many combinations around the following code:
> >.
> > [...]
> > 129    theLayer.rasterShader().setRasterShaderFunction(
> > QgsColorRampShader() )
> > 130    theLayer.setRasterShaderFunction( QgsColorRampShader() )
> > 131    myColorRampShader = QgsColorRampShader()
> > 132    myColorRampShader.setColorRampItemList( theTBL )
> > 133    myColorRampShader.setMaximumColorCacheSize( nColo )
> > 134    myColorRampShader.setColorRampType( myColorRampShader.DISCRETE )
> > 135    theLayer.rasterShader().setRasterShaderFunction(
> myColorRampShader )
> > 136    theLayer.setRasterShaderFunction( myColorRampShader )
>
> Hi Benoit,
>
> I've took a look at the problem at it turned out there were actually
> two problems with python wrappers. I've fixed that in svn - r14022.
> From that revision, things should werk correctly. You should be able
> to either:
> - create an instance of shader function and assign it to raster layer
> without a crash
> - retrieve current raster shader function and modify it (previously
> always the base class QgsRasterShaderFunction was returned)
>
> Regards
> Martin

_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to