Converting Vertical Units in a Digital Elevation Model

Sometimes you need to convert the vertical units in a digital elevation model (DEM). And sometimes you have to do it for a whole bunch of DEMs. Not everyone has a high-end GIS package with good batch processing capability, so what can you do? Luckily there is some very good free and open source software that can help you do the job. Today we’re going to look at converting a DEM between feet and meters using GDAL.

The specific program we’re going to use is GDAL_translate. When I first read the docs for it, I didn’t think it could do what I needed. It wasn’t until I got into the code to add what I wanted that I realized it was already there. I’m writing this under the assumption that I’m not alone in missing the obvious.

What I’d missed was how to use the -scale argument. Based on the name, it certainly looks like the right thing. However, it’s written as if your goal is something like re-scaling a band to use the full scale (e.g. expand it to use 0 to 255). You have to provide the min and max for input and output. When you look in the code, you realize it is using that to compute a scale and offset, which is just what you’d need to convert. So, here’s an example of the arguments to convert from feet to meters:

gdal_translate -scale 0 1 0 0.3048 inputfeet.tif outputmeters.tif

That essentially says that 1 foot is 0.3048 meters with a zero intercept. To go from meters to feet, you just swap the scale arguments:

gdal_translate -scale 0 0.3048 0 1 inputmeters.tif outputfeet.tif

To do lots of them, you simply use you favorite shell, such as Bash, Powershell, or CMD, to loop over the files you need to do. Here’s a somewhat lazy Bash example to do all the files in a directory:

mkdir meters
for file in *.tif
  gdal_translate -scale 0 1 0 0.3048 $file meters/$file

One of the best things about GDAL and GDAL_translate is that they understand a lot of different file formats. I used a TIFF as my example, but many formats that hold floating point numbers can work too. Plus, the output format doesn’t need to be the same as the input format.

Leave a Reply. Comments are moderated.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s