gdaldem for SRTM translation

Working on a static render of my SRTM tiles. Decided to use gdaldem to do the color mapping, it does all I need.

First I needed gdal 1.7 to use gdaldem, but Debian still packages older versions. There’s a lot of instructions for compiling. Long story short, ./configure; make works fine. It’s 1 million lines of code, so I had a nice cup of coffee.

Here’s how to use gdaldem to turn an SRTM .hgt file into a PNG: gdaldem color-relief -alpha -of png N39W120.hgt nelson.cmap gdaldem.png. There’s a variety of color map options, I hand-coded my own:

30000   180     0       0       255
4572    180     0       0       255
3049    130     80      80      255
3048    80      80      80      255
2438    0       0       0       255
2437    0       0       0       0
0       0       0       0       0
nv      0       255     0       255

That maps everything from 0-2437 meters (8000′) to transparent, then a grey ramp up to 10000′, then a red ramp up to 15000′, then solid red. Missing values (NV) are coloured green; need to deal with them later. The result looks like this

Now a bit of shell scripting to run the whole set:

for f in *.hgt; do
  ../experiment/gdaldem color-relief -alpha -of png $f ../png/nelson.cmap ../png/${f%.hgt}.png;

It’s awfully fast, I’m impressed with GDAL speed. The output PNG isn’t so bad, either, the empty tiles end up being 2k or so each.

Next up: to turn these into tiles I can serve for a slippy map. I might need to gdalbuildvrt first to combine all the files into one big virtual map.