NASA’s SRTM Elevation data

A simple C++ interface to NASA’s SRTM Elevation data. I use this code in my Flood Maps project. This code will only run on a Unix operating system.

Download it here: nasagrid.tgz

You can read about this data here:

You can download the data by FTP from:

SRTM3 is ready to use, and covers the whole world. SRTM1 has 3 times the resolution of SRTM3, but it only covers North America, and the file naming scheme is somewhat haphazard, so you’ll need to manually rename some of the files before you can use them.


1. Get the data files

Set the environment variable ROOT_PATH to tell the code where to find the data files. (You can also set the C++ macro ROOT_PATH, to the same effect.)

Create a directory called $ROOT_PATH/data.

Download the datafiles you require, and place them into your new directory. Unzip them. You don’t need to get all of the files. Any missing files will be skipped, and the software will tell you that those areas have “NO_DATA”.

The file names should follow NASA’s ‘SRTM3′ naming scheme. The case is IMPORTANT. Here are examples of valid file names…


2. Write your code

The interface is quite simple. Construct a Grid object, and call its height() method to get the height above mean sea level for a given lat/long coordinate. Here’s a very simple example.

 #include "grid.h"
 #include "nasagridsquare.h"

 int main() {
   float lat,lng;
   std::cin >> lat >> lng;
   Grid<NasaGridSquare> g;
   std::cout << g.height(lng,lat) << std::endl;
   return 0;

The Grid class caches the most recently used 360 data files in memory, in order to improve performance. If you have less than a Gigabyte of memory, you might need to reduce this number. (Of course, if you have much more memory, you could increase the limit.)

Set the cache limit like this:

  Grid<NasaGridSquare>::cache_limit = 100;

3. Publish your source code.

This software is licensed under the GPL. If you wish to redistribute it, then remember to comply with the terms.

Comment · Comments Feed · TrackBack

  1. Anthea said,

    29 August, 2006 @ 09:49

    I have been amazed that your data is the first to be available on the net – well done. I wondered if you could put some brain power on the possiblity of ocean plates moving allowing sulphur into the ocean from h2so4 mixed with NaCl to form an acidic ocean of HCl. This hypothosese is not mentioned on the web. Further rock erosion due to acid attack. Plus new land mass being created due to volcanic deposits.

  2. Matt said,

    30 October, 2007 @ 19:45

    I thought you might be interested in a similar web app to access SRTM and NED data. I’ve tested it in Firefox and IE, but I’m not total sure if it runs under UNIX OS. The web app is located at:



  3. Thomas said,

    5 May, 2009 @ 11:51

    Does this handle interpolation, i.e. give an arbitrary lat-long rather than one aligned to some grid?

  4. Fathi Shaqour said,

    20 July, 2009 @ 04:49

    I have been trying to download dem for the last 4 weeks or more with no success. Could you help please.



  5. Siddharth K said,

    27 March, 2011 @ 08:54


    I need to work with .hgt files for a summer project of mine. I downloaded your libraries and tried your sample code given above, but I am getting this error:

    /tmp/ccDir6Eb.o: In function Grid<NasaGridSquare>::height(float, float) const': test.cpp:(.text._ZNK4GridI14NasaGridSquareE6heightEff[Grid<NasaGridSquare>::heig ht(float, float) const]+0xe7): undefined reference toNasaGridSquare::NasaGridS quare(int, int)’ collect2: ld returned 1 exit status

    What am I doing wrong? Please help!

    Thank you

  6. aljwahery said,

    24 December, 2011 @ 19:15


  7. adel said,

    28 February, 2012 @ 19:09


  8. arindam said,

    13 March, 2012 @ 05:59

    sir, ihave been trying since last couple of day to dowload dem, but with no sucess. please help me in these regard. thank you.

Leave a Comment