[gdal-dev] SetColorTable() issues on GTiff with python bindings

Even Rouault even.rouault at mines-paris.org
Thu Sep 27 07:39:40 PDT 2012


Selon Ingmar N <initze at ucc.ie>:

> Hello,
> I would like to add a Colortable to a GeoTiff. Running the SetColorTable()
> function, python returns "3". GetColorTable() returns empty, no colortable
> is attached.
> After browsing the internet for a solution, I tried to run the procedure on
> a newly created GTiff (which was often suggested). Probably any issues with
> the colortable?
> The file is not Write-protected or problematic otherwise, WriteArray() for
> example works without any problem.
>
>
>
ds2=dr.Create('C:\\testfolder\\X.tif',ds.RasterXSize,ds.RasterYSize,1,gdal.GDT_Int16)
> ct=gdal.ColorTable()
> ct.CreateColorRamp(0,(178,223,138),5,(255,127,0))
> outband=ds2.GetRasterBand(1)
> outband.SetColorTable(ct) # returns 3
>
> Versions:
> python 2.7
> gdal 1.9.1
>
> Any Suggestions?

You should have seen the following error emitted in the console :
"SetColorTable() only supported for Byte or UInt16 bands in TIFF format." . The
data type asked in Create() is Int16, not Byte or UInt16.


More information about the gdal-dev mailing list