2

I am trying to convert a geoTIFF to a kml with gdal_translate -of KMLSUPEROVERLAY, however I don't know how to do so with a color gradient.

My geotiff is an 8bit raster with valid values ranging from 0-100. I'd like a simple output where 0-10 is gray, and 11-100 has a one-color gradient from light to dark (say, purple). This could be in classes of 11-20, 21-30, etc. or whatever, as long as it goes from light to dark.

Is this possible?

Is there a way to supply a color table with values and their corresponding RGB values? I see some options on gdal_translate but don't know where to start.

3

Found a solution to my problem:

gdaldem color-relief -nearest_color_entry -alpha -co format=png -of KMLSUPEROVERLAY raster.tif color.txt raster-kml.kmz

gdaldem color-relief converts a grayscale tiff to a multiband RGB(A) tiff

'-alpha' says my color table has an alpha band (which controls transparency)

'-co format=png' outputs the tiles in .png instead of the default .jpg, because the latter does not support transparency (How can I create a kml file from a geotiff with alpha layer)

'-of KMLSUPEROVERLAY' says my output type is kml/kmz. I specified a .kmz extension because it puts all the tile layers/kmls into one file that GoogleEarth can read

Lastly, color.txt looks like this:

0 240 240 240 0
1 205 205 205 255
20 214 174 250 255
30 203 161 240 255
40 192 149 231 255
50 181 136 222 255
60 171 124 213 255
70 160 111 203 255
80 149 99 194 255
90 138 86 185 255
101 128 74 176 255
nv 240 240 240 0

Values of 0 and NoData are fully transparent, 1-20 is gray, and 20-100 have a light-dark purple gradient with classes of 10.

  • Way to come back and post your solution. A+ on you, good internet patron. – four43 Apr 24 at 14:51

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.