Elevation data is crucial when mapping places like Afghanistan and Pakistan, given the mountainous terrain. The GIST project provides elevation data of the countries from the Shuttle Radar Topography Mission (STRM) in rasterized GeoTiff format. But working with raster data demands a totally different set of tools than working with vector formats like shapefiles. Luckily the open source GDAL project provides an excellent set of tools for manipulating these files.
A few brand new tools in the set, called gdaldem, allow you to make things like hillshades and color relief maps. Hillshades use the raw elevation data to create cast shadows on the side of mountains or hills, and color relief maps create images that portray each level of elevation in a different color. The two can be combined for an amazing effect.
Here is a hillshade:
Here is a color relief map:
Here are the two combined:
Below are the steps to create these images based on a excellent tutorial from DM Solutions Group.
- Install GDAL. As of this writing, the new tools are only available in the development version, so you will need to compile from SVN Trunk or use a nightly snapshot.
My source files were a series of nine GeoTiffs (four from Afghanistan and five from Pakistan). The first thing I did was use gdal_megrge.py to combine them into one massive 1.4 GB file.
$ gdal_merge.py -o afpak_merged.tif ../afghanistan_srtm*/afghanistan_srtm.tif ../pakistan_srtm_/pakistan_srtm_*.tif
Create the hillshade.
$ gdaldem hillshade afpak_merged.tif hillshade_afpak.tif -z 5 -s 111120
Create the color relief. You need to set up a config file that tells this command what color to use for each elevation. Here's the one I used and I saved it in a file called ramp.txt.
3500 255 255 255 2500 235 220 175 1500 190 185 135 700 240 250 150 0 50 180 50 -32768 200 230 255
And here is the command.
$ gdaldem color-relief afpak_merged.tif ramp.txt color_relief_afpak.tif
Finally, we wanted to re-project each file to the Google Projection. I tried to do this right after merging the files, but it seemed to wipe the data from the file. It's not a huge problem just to do it on each file separately.
$ gdalwarp -s_srs EPSG:4326 -t_srs EPSG:900913 color_relief_afpak.tif color_relief_afpak_goog.tif $ gdalwarp -s_srs EPSG:4326 -t_srs EPSG:900913 color_relief_afpak.tif color_relief_afpak_goog.tif
The final result is two large TIF files. Import these into QGIS and put the hillshade on top set to 70% transparency. Looks great!
Up to this point, the tile rendering infrastructure that we've been working on did not support raster data. This was because we centered our workflow around the PostgreSQL database as the sole datasource. PostgreSQL can only store vector data, so we're now using S3 to store our raster files. The files are automatically downloaded by the render nodes when there are needed.