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

Peter Ersts ersts at amnh.org
Thu Aug 12 10:25:19 EDT 2010


On 08/10/2010 03:46 PM, Martin Dobias wrote:
> I believe this can be fixed easily by testing whether the new shader
> function isn't the same as the previous one in
> setRasterShaderFunction(). Do you see any further scenarios that might
> lead to a crash? Because deleting the shader function in the class
> where it belongs is typically less prone to memory leaks or double
> deletion.
>
> Bye
> Martin
>
>    

Howdy Martin.

I think this is a good solution. I was thinking of the same approach.

Another potential situation that could lead to a crash would be sharing 
a custom shader between raster layers.

Without going into too much detail, say you wrote a custom app/plugin to 
display several adjacent rasters (maybe aerial images along a transect), 
and they all needed to be shaded the same way, with your custom shader. 
Right now, you can set the shader for all layers to the same shader and 
things would work ok until you changed the shader for any one layer. 
Granted there are external work arounds ( mosaics etc.) and you could 
just duplicate the shader for each layer as they are quite small, 
however reusing the shader seems like it should be an option for smaller 
memory devices -- and the color cache can actually get quite large 
depending on the type of image.

Safe pointers come to mind, but I think we may just be able to add an 
extra flag to the setRasterShaderFunction() that would allow you to 
override the delete on change functionality:

void QgsRasterShader::setRasterShaderFunction( QgsRasterShaderFunction*, 
bool deleteOnChange=true)

So calling setRasterShaderFunction( myFunc, false ) would mean that the 
next call to setRasterShaderFunction( ) would NOT attempt to free the 
point to the current shader function.

-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.



More information about the Qgis-developer mailing list