I'm new to rasterio. I have tried this example. My raster file is a GeoTIFF file and I have a colormap file available in ESRI *.clr format, with 58 lines. The values in the GeoTIFF file range from 10471 thru 10534. For those who don't know the format, the first 2 lines looks like this:
10471 16 24 79
10472 104 223 247
I have read a bit about colormaps, e.g. here. I read this: "You cannot set the color interpretation on existing data". All the same, I'm hoping that I can have the colormap applied to the plotted raster in a direct way, but I have no idea how to go about it. In order to start somewhere, I wrote this code:
import csv
import os.path
import sys
cf = None
try:
curdir = os.path.dirname(sys.argv[0])
datapath = os.path.normpath(os.path.join(curdir, "../geodata/EUR"))
cf = open(os.path.join(datapath, "countries.clr"), "r")
rows = {}
for row in (csv.reader(cf, delimiter=' ')):
color = tuple([int(row[1]), int(row[2]), int(row[3]), 255])
rows[int(row[0])] = color
# Do we almost have a colormap now?
finally:
if cf != None: cf.close()
Later on, I'd also like to indicate that rasterio should plot classes - defined somehow - in different colours. I'm afraid that it's only possible to get this working in an indirect way - with some time-consuming tricks - but if you can, please surprise me!