View Full Version : [Award Winner] Managing SRTM information with GDAL

04-28-2009, 11:09 AM
The information from NASA's Shuttle Radar Topography Mission (SRTM) can be used as a basis for hillsades or elevations in fantasy maps. In this tutorial we're going to see how to manage this data using OSGeo Foundation GDAL library. We're going to use this library from the command line utilities included in FWTools (http://fwtools.maptools.org/).

The idea is to convert the image Figure 1 into the image Figure 2. Well not exactly the image Figure 2, but at least how to obtain the base information:

Figure 1
Figure 2

1.- Getting the data.

You can get NASA's SRTM data from several sources:

NASA's FTP (ftp://e0srp01u.ecs.nasa.gov/srtm/).
USGS webpage (http://seamless.usgs.gov/index.php).
a Google Earth layer from Mark Mulligan and the London's King's College (http://www.ambiotek.com/topoview).

Each source has it's pros and cons. If you are using the NASA's FTP you must first know the coordinates of the zone you want to use and what you get are tiles, in the USGS webpage you can get some crops of the zone you want to use, it's better to use this source if you are using small zones or your zone is in between several tiles, with the Google Earth layer you can also get tiles, and in several formats as ARCASCII or GeoTiff.

04-28-2009, 11:09 AM
I will use the Google Earth layer though it is easyer to use the USGS webpage. On image Figure 3 you can see the Google Earth layer tiles. If you make click on the icon in the center of the tile you'll get a dialog similar to the one on the image Figure 4, were you can find the download link. For example, I need four GeoTiff tiles to cover the all the territory of the Comunidad Valenciana, the place where I live.

Figure 3
Figure 4

Once you have all the zip files that you need you can unzip them in a directory.

2.- Working with FWTools.

I'm going to supouse that you have already downloaded and installed FWTools (v2.2.8 in my case, though I think there's a new version right now), I'm not covering the installation stuff, only two Caveat emptor if you are using FWTools in Windows:

Remember to run setfw.bat, wich is in the installation directory, before start working.
Any of the Python scripts of FWTools that you may run, have to be ran with the Python installation that comes with FWTools, You have to use the entire path to the python.exe that comes with FWTools and the entire path to the script .py you want to run.

I'm not going to write the entire paths in this tutorial, remember to write them, OK?.

04-28-2009, 11:10 AM
3.-Joinning the tiles.

We're going to use gdal_merge for joinning the tiles, it's a console apllication (a command) for joinning raster datasets. I you type:


you will get a lot of information about this command, but I'm just getting to the meat of the matter:

If we have four tiles files srtm_36_04.tif, srtm_36_05.tif, srtm_37_04.tif y srtm_37_05.tif; you can join them typping:

gdal_merge -o mosaico.tif srtm_36_04.tif srtm_36_05.tif srtm_37_04.tif srtm_37_05.tif

After -o comes the name of the output file, after that comes the names of the files, space sepparated; though the desired output format is the same that the standard (GeoTiff) we're not using the -of option.

4.- Cropping.

For cropping we are going to use gdalwarp.

gdalwarp -te 626680 4191038 815725 4519394 mosaico.tif mosaico_rer.tif

after the -te option you must add the area coordinates

04-28-2009, 11:10 AM
5.- Scaling.

If you use Photoshop this is the end of the mini-tutorial, you can get the final image and start working with it.

But I use GIMP and we won't get 16bit image support until version 2.8 (if they don't change the milestone again) so I have to scale the images to 8 bits.

We'll use gdal_translate command for rescaling, but we're also using gdalinfo for getting some info first. With gdalinfo we can get information about the maximum and minimum of the histogram, we will use this information for rescaling to 0~255 greyscale with gdal_translate. For getting the info we type

gdalinfo -hist mosaico_rer.tif

we are looking for a line wich is similar to " 256 buckets from -32835.4 to 1757". -32835.4 is a way to say NULL or no data, and 1757 is the maximum.

gdal_translate -ot Byte -scale 0 1757 0 255 mosaico_rer.tif mosaico_rer8.tif

With the -ot option you can set the output data type, we are using 8 bit (1 byte), and again the output format is GeoTiff, the standard one; so we're not using the -of option. With the -scale option you can define the match between the input (0~1757) and output (0~255) range.

Now you can use the image in GIMP.

04-28-2009, 08:33 PM
Good stuff. I was able to follow along and understand even though I have no knowledge of using real world data. I can see this as being very helpful and useful. Good job.

05-02-2009, 03:32 AM
Amazing...thanks very much for posting this and have some rep. I can see myself using it when I want to make a real world map.

05-02-2009, 11:49 AM
Yup, I have had visions of doing stuff like this....just never knew how though.

Thanks vehrka, have some rep 8)

Got a question for you....are these progs free and where do you get them?

I looked through Google Earth (basic, no add-ons) and couldn't come up with those tiles...What am I missing?

05-05-2009, 10:47 AM
Cool to see someone using some of the real world tools out there to make their own maps. I'm a remote sensing guy myself and use GDAL and GIS tools every day, but haven't delved yet into using some of the RS software I have to map creation.

05-05-2009, 11:46 AM
@Korash: Those programs are not only free, but open source, you can download them as a pack with FWTools (you have the link in the first post, click on FWTools). For Google Earth you have to download the KMZ file (again click on the link in point 1)

Thanks for the rep guys!

05-05-2009, 12:33 PM

Yup, figured that out and downloaded after I asked. I tried it out but am having trouble with the gdalinfo command = are you supposed to put the entire path to the file you are looking at? what is the "_rer" for? do we need to put it inthe file name?put the path before or after the "-hist"?

I am stuck here.

05-08-2009, 03:27 AM
Hello Korash!

The "_rer" is just stuck to the name to diferenciate the input file and the output file, there was an error in the naming in step 4 I was using mosaico_re.tif instead of mosaico.tif, I've edited the post and hope it is clearer now.

I usually run the commands in the same directory where the image files are, so there is no need for incluiding the entire path to the file when you run the command.

Hope this helps!

05-08-2009, 12:15 PM

the ol' "/cd" command....

should have remembered that....

Please forgive an old timer who hasn't touched DOS since school and never before that ;)

much clearer now thanks muchly. I will try this again this weekend. :)

05-08-2009, 11:43 PM
Well that works quite nicely!! 8)

I have attached a map of the Falkland Islands that I generated with this method in about 5 minutes after completing these steps outlined above. I ran the generated height field as a bump map 3 times to get the higher mountains.

The res is not all that great 'cause when I opened the file in gimp it was set at 72 px. I cropped it in Gimp because I didn't have the coords on hand to do in FWtools, but I think that it shows the value of using the method none the less

Repped and 5 rated by me at least :D

:edit: need to spread the love some more before I can rep you again. Sorry.

05-09-2009, 12:18 AM
I just have one word (but it requires me to type at least 10 letters)...excellent!

05-18-2009, 10:40 AM
Very nice beginning!

08-21-2009, 10:59 AM
I'm using the Google Earth overlays to get the SRTM data in ARCASCII...but I use MICRODEM (also free) to manipulate it...its pretty cool. trying to find the link to the offsite tutorial on here.

08-21-2009, 11:05 AM
Pretty cool stuff I have to say. :)

08-21-2009, 11:05 AM
found it: http://www.cartographersguild.com/showthread.php?t=507