0

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)
  location.persist()

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 – Stephen Ruhl Feb 17 '17 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. – Joshua Coady Feb 17 '17 at 20:27
  • What server are you using (e.g. Oracle, PostgresSQL, etc)? – Stephen Ruhl Feb 17 '17 at 20:31
  • Linux, data store will likely be NoSQL, maybe mongo or dynamodb. – Joshua Coady Feb 17 '17 at 20:37
  • I added an example of code of what I want to do. The data store shouldn't really matter. I may end up also wanting to do this on the fly without the DB as well. I just want to be able to give an API lat/lon and get back the corresponding elevation. I can download and install the API and the elevation data onto the server and get them hooked up together, I just need to know what's the best source for the data and what API would know how to use that data to extract elevation info. – Joshua Coady Feb 17 '17 at 20:55
4

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? – Joshua Coady Feb 18 '17 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? – Joshua Coady Feb 18 '17 at 19:46
  • It would work for any raster format that rasterio can read – user2856 Feb 18 '17 at 19:49
  • You can look into mosaicing individual rasters – user2856 Feb 18 '17 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/… – Joshua Coady Mar 24 '17 at 0:01

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.