[Qgis-developer] How to load a colour table on a raster, programmatically (in python)?

Benoit de Cabissole benoit at exigesa.com
Thu Aug 5 11:37:35 EDT 2010


Hi Peter,

Many, many thanks for that.

Anyway, QGIS is throwing many exceptions at my code! Need to understand how
things work...

Thanks again!
Benoit

> -----Original Message-----
> From: qgis-developer-bounces at lists.osgeo.org
> [mailto:qgis-developer-bounces at lists.osgeo.org]On Behalf Of Peter Ersts
> Sent: Thursday, 05 August 2010 15:33
> To: qgis-developer at lists.osgeo.org
> Subject: Re: [Qgis-developer] How to load a colour table on a
> raster,programmatically (in python)?
>
>
> On 08/05/2010 05:25 AM, Benoit de Cabissole wrote:
> > Could you please point me to the function(s) that are used to
> match a custom
> > colour table (QgsColorRampShader?) to a raster?
> >
> >
>
> Howdy Benoit,
>
> First you will need to set the color shading algorithm for the raster,
>  >> YourRasterLayer.setColorShadingAlgorithm( "ColorRampShader" )
> This creates a new shader for the raster.
>
> Next you will need to build your color ramp (palette). This is just a
> list of items of type QgsColorRampShader.ColorRampItem, Each item has
> three variables, lable (QString), color (QColor) , and value (double)
>
> Once you have your list you will need to give that list to the shader.
>  >> YourRasterLayer.rasterShader().setColorRampItemList( YourColorRamp )
>
> Then you need to set the color ramp type:
>  >> YourRasterLayer.rasterShader().setColorRampType( TheType )
>
> Where TheType is, INTERPOLATED, DISCRETE or EXACT. If your color ramp
> only had three entries:
> Label1, Red, 0
> Label2, Yellow, 127
> Label3, Green, 255
>
> exact - looks for an exact match at the time of shading, a value of 90
> would not be shaded.
>
> discrete - is a bin type approach, images pixels with values of 50, 70,
> or 90 would all be assigned the same color
>
> interpolated - is as the name says, 90 will be an interpolated color
> between Red and Yellow. In this case, more yellow than red as 90 is
> closer to 127 than 0.
>
>
> Hope that helps.
> -pete
>
> --
> ====================================
> Peter J. Ersts, Software Developer
> American Museum of Natural History
> Center for Biodiversity and Conservation
> Central Park West at 79th Street
> New York, New York 10024
> Web: http://biodiversityinformatics.amnh.org
> Web: http://cbc.amnh.org
>
> Open Source,
> ...evolving through community cooperation to change the world bit by bit
>
> Quantum GIS Raster Development Team.
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the Qgis-developer mailing list