0

I am trying to embed a color table into a raster using Python and GDAL without success. I was trying to follow the example here

colors = gdal.ColorTable()
with open(color, 'r') as f:
lines = f.readlines()
for line in lines:
    temp = tuple(line.split(" ")[:4])
    tempi = [eval(i) for i in temp]
    send = tempi[0], tuple(tempi[1:4])
    print(send)
    colors.SetColorEntry(send)

this is this first item sent to colors.SetColorEntry (from a call to print)

(1, (115, 92, 64))

and traceback shows the error

TypeError: ColorTable_SetColorEntry expected 3 arguments, got 2

Can anyone shed some light on this and send me in the right direction? What other argument is it wanting?

palabria
  • 11
  • 3

1 Answers1

0

This error is due to Python way of taking function arguments. You can modify your last line as below and check. The rest can remain the same.

colors.SetColorEntry(*send)

send is a tuple. The function SetColorEntry expects 2 arguments, (1) the pixel value, and (2) the RGB color as a tuple. You are generating all the data correctly, but instead of passing the required values to the function as it expects, you are "packing" it to another variable/tuple (send). The * symbol before the tuple, "unpacks" the values and passes to the function.

PKG
  • 610
  • 3
  • 12