I have found code which returns a single lat long point, but it takes about 1s per point. I would like to get an altitude map of an area between 2 sets of lat/lon coords. Ideally not with the googleapi because that requires a key.
My code (which I stole from another post) that gets a single lat/lon point:
import requests
import urllib
import pandas as pd
# USGS Elevation Point Query Service
url = r'https://nationalmap.gov/epqs/pqs.php?'
# coordinates with known elevation
lat = [48.633, 48.733, 45.1947]
lon = [-93.9667, -94.6167, -93.3257]
# create data frame
df = pd.DataFrame({
'lat': lat,
'lon': lon
})
def elevation_function(df, lat_column, lon_column):
"""Query service using lat, lon. add the elevation values as a new column."""
elevations = []
for lat, lon in zip(df[lat_column], df[lon_column]):
# define rest query params
params = {
'output': 'json',
'x': lon,
'y': lat,
'units': 'Meters'
}
# format query string and return query value
result = requests.get((url + urllib.parse.urlencode(params)))
elevations.append(result.json()['USGS_Elevation_Point_Query_Service']['Elevation_Query']['Elevation'])
df['elev_meters'] = elevations
elevation_function(df, 'lat', 'lon')
print(df)
df.head()
Which returns:
lat lon elev_meters
0 48.6330 -93.9667 341.14
1 48.7330 -94.6167 328.80
2 45.1947 -93.3257 262.68
How would I get an altitude map? Not using this because this takes way too long.