Ticket #2227: extract_ctable.py

File extract_ctable.py, 458 bytes (added by Vlad Merticariu, 5 years ago)
Line 
1import gdal
2import json
3import sys
4
5if len(sys.argv) < 3:
6 print "Required positional arguments: file path, output path."
7 exit(1)
8else:
9 fname = sys.argv[1]
10 oname = sys.argv[2]
11
12f = gdal.Open(fname)
13band = f.GetRasterBand(1)
14ct = band.GetRasterColorTable()
15clist = []
16for i in range(ct.GetCount()):
17 clist.append(list(ct.GetColorEntry(i)))
18
19result = {}
20result["colorTable"] = clist
21
22with open(oname, "w") as ofile:
23 ofile.write(json.dumps(result))