[Gdal-dev] Changing a color in palette

Frank Warmerdam warmerdam at pobox.com
Fri Jan 23 17:06:42 EST 2009


darrepac wrote:
> If I have to do a script in Python, I will do it!
> So yes please, I would like to see an example

Darre,

With GDAL "trunk" the following seems to do the trick, and could
be easily extended to loop over many files.


import gdal


def update_ct( file ):

     ds = gdal.Open( file, gdal.GA_Update )

     ct = ds.GetRasterBand(1).GetRasterColorTable()

     ct.SetColorEntry( 123, (255,255,255) )

     ds.GetRasterBand(1).SetRasterColorTable( ct )

     ds = None



update_ct( 'test.tif' )


Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list