<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; ">Let me adjust my question. I changed the color-table code to:<div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font face="Courier New">c = gdal.ColorTable(gdal.GCI_PaletteIndex)</font></div></div><div><div><font face="Courier New">n = c.SetColorEntry(1,[255,128,0,0])</font></div></div><div><div><font face="Courier New">m = c.SetColorEntry(65535,[0,128,255,255])</font></div></div><div><div><font face="Courier New">c.CreateColorRamp(1,n,65535,m)</font></div></div><div><div><font face="Courier New">band.SetColorTable(c)</font></div></div></blockquote><div><div><br></div><div>I discovered that the 64K colors are due to the UInt16 (tested GDT_Byte and got 255) so i realized that maybe i need to create a ramp?</div><div><br></div><div>But the above code fails with:</div><div><br></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><font face="Courier New">Traceback (most recent call last):</font></div></div></div><div><div><div><font face="Courier New"> File "makecolortable.py", line 14, in <module></font></div></div></div><div><div><div><font face="Courier New"> n = c.SetColorEntry(1,[255,128,0,0])</font></div></div></div><div><div><div><font face="Courier New"> File "/usr/lib/python2.7/dist-packages/osgeo/gdal.py", line 1113, in SetColorEntry</font></div></div></div><div><div><div><font face="Courier New"> return _gdal.ColorTable_SetColorEntry(self, *args)</font></div></div></div><div><div><div><font face="Courier New" color="#ff2619"><b>TypeError: Invalid values in ColorEntry sequence </b></font></div></div></div></blockquote><div><div><br></div><div>That sequence appears correct as all four values meet the short requirement, (i think this is the code that produces the error):</div><div><br></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><pre style="word-wrap: break-word; white-space: pre-wrap; "><font face="Courier New">if ( !PyArg_ParseTuple( $input,"hhh|h", &ce.c1, &ce.c2, &ce.c3, &ce.c4 ) ) {</font></pre><pre style="word-wrap: break-word; white-space: pre-wrap; "><pre style="word-wrap: break-word; white-space: pre-wrap; "><font face="Courier New"> PyErr_SetString(PyExc_TypeError, "Invalid values in ColorEntry sequence ");</font></pre></pre></div></div></blockquote><div><div><br></div><div><br></div><div>
--nix
</div>
<br><div><div>On Mar 8, 2013, at 16:35, Robert Nix <<a href="mailto:robert@urban4m.com">robert@urban4m.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div 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><font face="Courier New">import numpy as np</font></div><div><font face="Courier New">import gdal</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">driver = gdal.GetDriverByName('GTiff')</font></div><div><font face="Courier New">dst_ds = driver.Create('testcolor.tif', 100, 100, 1, gdal.GDT_UInt16)</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">band = dst_ds.GetRasterBand(1)</font></div><div><font face="Courier New">band.SetRasterColorInterpretation(gdal.GCI_PaletteIndex)</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New" color="#0b33ff">c = gdal.ColorTable(gdal.GCI_PaletteIndex)</font></div><div><font face="Courier New" color="#0b33ff">c.SetColorEntry(1,(255,127,0,63))</font></div><div><font face="Courier New" color="#0b33ff">band.SetColorTable(c)</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">a = np.random.randint(1,10,size=(100,100))</font></div><div><font face="Courier New">band.WriteArray(a)</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">dst_ds = None</font></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><font face="Courier New">Driver: GTiff/GeoTIFF</font></div><div><font face="Courier New">Files: testcolor.tif</font></div><div><font face="Courier New"> testcolor.tif.aux.xml</font></div><div><font face="Courier New">Size is 100, 100</font></div><div><font face="Courier New">Coordinate System is `'</font></div><div><font face="Courier New">Image Structure Metadata:</font></div><div><font face="Courier New"> INTERLEAVE=BAND</font></div><div><font face="Courier New">Corner Coordinates:</font></div><div><font face="Courier New">Upper Left ( 0.0, 0.0)</font></div><div><font face="Courier New">Lower Left ( 0.0, 100.0)</font></div><div><font face="Courier New">Upper Right ( 100.0, 0.0)</font></div><div><font face="Courier New">Lower Right ( 100.0, 100.0)</font></div><div><font face="Courier New">Center ( 50.0, 50.0)</font></div><div><font face="Courier New">Band 1 Block=100x40 Type=UInt16, ColorInterp=Palette</font></div><div><font face="Courier New"> Color Table (RGB with 65536 entries)</font></div><div><font face="Courier New"> 0: 1,0,0,255</font></div><div><font face="Courier New"> 1: 1,0,0,255</font></div><div><font face="Courier New"> 2: 0,0,0,255</font></div><div><font face="Courier New"> 3: 0,0,0,255</font></div><div><font face="Courier New">...</font></div><div><font face="Courier New"> 65533: 0,0,0,255</font></div><div><font face="Courier New"> 65534: 0,0,0,255</font></div><div><font face="Courier New"> 65535: 0,0,0,255</font></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></div></blockquote></div><br></div></body></html>