I would prefer something in python (but I would settle for any programming language) and something that I could install on my own server so the only limitations would be hardware (no throttling, no daily request limits, etc). i.e. I'm not interested in using a hosted service like Google Maps API.

What I want to be able to do is something like:

for location in locations_data_store:
  location.elevation = some_module.lookup_elevation(location.lat, location.lon)

Or, it could be more involved than that. I don't mind making a REST API request, parsing some JSON, or in some other way more complex programmatically.

  • What GIS software/environment are you planning on using? The National Map Viewer has elevation data from USGS in 1/3 arc sec for most of the USA. viewer.nationalmap.gov/basic Feb 17, 2017 at 20:16
  • No software, this is purely programmatic on a server with no UI. I have a big list of coords in a DB that I want to add elevation data to. Feb 17, 2017 at 20:27
  • What server are you using (e.g. Oracle, PostgresSQL, etc)? Feb 17, 2017 at 20:31
  • Linux, data store will likely be NoSQL, maybe mongo or dynamodb. Feb 17, 2017 at 20:37
  • 1
    Please edit the question to contain your question. Eight long comments is eight comments too many.
    – Vince
    Feb 18, 2017 at 2:04

2 Answers 2


You can use the rasterio library:

import rasterio

coords = ((147.363,-36.419), (147.361,-36.430))
elevation = 'srtm_66_20.tif'

with rasterio.open(elevation) as src:
    vals = src.sample(coords)
    for val in vals:
        print(val[0]) #val is an array of values, 1 element 
                      #per band. src is a single band raster 
                      #so we only need val[0]

The example above uses the SRTM digital elevation model (DEM), but there are others available depending on your area of interest and resolution requirements.

Note the example is simple as SRTM data is available in a geographic coordinate system, there are a few more steps if your DEM is in a different projection.

  • Seems like SRTM comes with multiple 'tif' files--how do you know which one to use? Feb 18, 2017 at 19:44
  • Would this work for any data source that is provided as a 'tif' file as long as the coords are adjusted to the correct projection? Feb 18, 2017 at 19:46
  • It would work for any raster format that rasterio can read
    – user2856
    Feb 18, 2017 at 19:49
  • You can look into mosaicing individual rasters
    – user2856
    Feb 18, 2017 at 19:50
  • Thanks, this is essentially what I ended up doing, just wrapped into a package that knows where the individual elevation files are located and can use the input coords to determine which file to use. I ended up going with the data from catalog.data.gov/dataset/… Mar 24, 2017 at 0:01

For the future users' convinience, when you provide lat lon in get_elevation function, it gives the elevation.

import rasterio
elevation_file = 'Dem.tif'
def get_elevation(lat, lon):
    coords = ((lat,lon), (lat,lon))
    with rasterio.open(elevation_file) as src:
        vals = src.sample(coords)
        for val in vals:
            return elevation
get_elevation(34, 36)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.