<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br><div>I'm trying to add a color table to a 1-band UInt16 GeoTiff with Python as follows:</div><div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font face="Courier New">import numpy as np</font></div></div><div><div><font face="Courier New">import gdal</font></div></div><div><div><font face="Courier New"><br></font></div></div><div><div><font face="Courier New">driver = gdal.GetDriverByName('GTiff')</font></div></div><div><div><font face="Courier New">dst_ds = driver.Create('testcolor.tif', 100, 100, 1, gdal.GDT_UInt16)</font></div></div><div><div><font face="Courier New"><br></font></div></div><div><div><font face="Courier New">band = dst_ds.GetRasterBand(1)</font></div></div><div><div><font face="Courier New">band.SetRasterColorInterpretation(gdal.GCI_PaletteIndex)</font></div></div><div><div><font face="Courier New"><br></font></div></div><div><div><font face="Courier New" color="#0b33ff">c = gdal.ColorTable(gdal.GCI_PaletteIndex)</font></div></div><div><div><font face="Courier New" color="#0b33ff">c.SetColorEntry(1,(255,127,0,63))</font></div></div><div><div><font face="Courier New" color="#0b33ff">band.SetColorTable(c)</font></div></div><div><div><font face="Courier New"><br></font></div></div><div><div><font face="Courier New">a = np.random.randint(1,10,size=(100,100))</font></div></div><div><div><font face="Courier New">band.WriteArray(a)</font></div></div><div><div><font face="Courier New"><br></font></div></div><div><div><font face="Courier New">dst_ds = None</font></div></div></blockquote><div><div><br></div><div>The problem is that when i run gdalinfo on the testcolor.tif, it lists 65535 color table entries:</div><div><br></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><font face="Courier New">Driver: GTiff/GeoTIFF</font></div></div></div><div><div><div><font face="Courier New">Files: testcolor.tif</font></div></div></div><div><div><div><font face="Courier New"> testcolor.tif.aux.xml</font></div></div></div><div><div><div><font face="Courier New">Size is 100, 100</font></div></div></div><div><div><div><font face="Courier New">Coordinate System is `'</font></div></div></div><div><div><div><font face="Courier New">Image Structure Metadata:</font></div></div></div><div><div><div><font face="Courier New"> INTERLEAVE=BAND</font></div></div></div><div><div><div><font face="Courier New">Corner Coordinates:</font></div></div></div><div><div><div><font face="Courier New">Upper Left ( 0.0, 0.0)</font></div></div></div><div><div><div><font face="Courier New">Lower Left ( 0.0, 100.0)</font></div></div></div><div><div><div><font face="Courier New">Upper Right ( 100.0, 0.0)</font></div></div></div><div><div><div><font face="Courier New">Lower Right ( 100.0, 100.0)</font></div></div></div><div><div><div><font face="Courier New">Center ( 50.0, 50.0)</font></div></div></div><div><div><div><font face="Courier New">Band 1 Block=100x40 Type=UInt16, ColorInterp=Palette</font></div></div></div><div><div><div><font face="Courier New"> Color Table (RGB with 65536 entries)</font></div></div></div><div><div><div><font face="Courier New"> 0: 1,0,0,255</font></div></div></div><div><div><div><font face="Courier New"> 1: 1,0,0,255</font></div></div></div><div><div><div><font face="Courier New"> 2: 0,0,0,255</font></div></div></div><div><div><div><font face="Courier New"> 3: 0,0,0,255</font></div></div></div><div><div><div><font face="Courier New">...</font></div></div></div><div><div><div><font face="Courier New"> 65533: 0,0,0,255</font></div></div></div><div><div><div><font face="Courier New"> 65534: 0,0,0,255</font></div></div></div><div><div><div><font face="Courier New"> 65535: 0,0,0,255</font></div></div></div></blockquote><div><div><br></div><div>What's going on … besides the fact that maybe i'm not understanding color-tables? If it's clear i don't understand, is there a good resource for understanding color-tables? Or must I go learn the source code (which i really don't have to do)?</div><div><br></div><div>Thanks</div><div>
--nix
</div>
<br></div></div></body></html>