Reputation: 788
can we use open-elevation with python? I tried to get the API using request and didn't work
#overpass api url
elevation_request = "https://api.open-elevation.com/api/v1/lookup\?locations\=10,10\|20,20\|41.161758,-8.583933"
elevation = requests.get(elevation_request)
data_json = elevation.json()
how can we integrate this API with python?
Upvotes: 1
Views: 3927
Reputation: 411
I am the author of https://open-elevation.com.
The service should be working much more reliably now.
Sadly, the service is widely used for free, but there is very little in the way of donations, so I have been unable to upgrade it properly to handle the load. A migration in the coming month (with more money coming out of my pocket each month) has eased this situation, but I can't tell you how long it will last.
Upvotes: 5
Reputation: 21
The endpoints are valid, but they are many times slow or sometimes unresponsive. The code below is an adaptation of this answer to deal with response status codes and timeout:
from requests import get
from pandas import json_normalize
def get_elevation(lat = None, long = None):
'''
script for returning elevation in m from lat, long
'''
if lat is None or long is None: return None
query = ('https://api.open-elevation.com/api/v1/lookup'
f'?locations={_lat},{_long}')
# Request with a timeout for slow responses
r = get(query, timeout = 20)
# Only get the json response in case of 200 or 201
if r.status_code == 200 or r.status_code == 201:
elevation = json_normalize(r.json(), 'results')['elevation'].values[0]
else:
elevation = None
return elevation
Upvotes: 1