1

I've been using a color ramp with fixed values (0-255) corresponding to specific rgb color (discrete interpolation) for 8bit tifs in QGIS. I've used matplotlib to apply built in colormaps, but I'm trying to figure out how to create a matplotlib custom colormap to replicate the results I get from QGIS that uses this fixed scale.

Example fixed value color ramp

# QGIS Generated Color Map Export File
# val, r, g, b, a, label
INTERPOLATION:INTERPOLATED
133,178,178,178,255,1
138,0,120,120,255,2
142,0,190,190,255,3 
... and so on

Any pointers on how to go about this? I was able to get fairly close with gdaldem color-relief but its interpolation is adjusting some of the values where it isn't quite as good as what QGIS is outputting... I'm assuming because its automatically using linear interpolation vs discrete

0

I never got a custom matplotlib colormap figured out, but I did get gdaldem working to produce the required output by using -nearest_color_entry and -alpha options.

gdaldem color-relief -nearest_color_entry -alpha -of PNG input.tif colors.txt output.png

colors.txt was structured like this:

133 178 178 178 255
138 0 120 120 255
142 0 190 190 255
....

The main issue I had before was not using gdaldem with -alpha and the last column with alpha values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.