有没有类似于谷歌地图的开放街图高程API呢?在谷歌高程API中,我们可以传递坐标,并得到海拔作为响应。
我最近发布了Open-Elevation,这是一个免费且开源的高程API,也可在Github上使用。我们提供免费的公共API以及有关如何设置产品自己实例的文档。
它还可以在Github上获得。
欢迎提交pull请求!
OpenStreetMap并没有包含太多高程数据。 https://help.openstreetmap.org/questions/3069/elevation-maps
https://api.opentopodata.org/v1/eudem25m?locations=50.7827,6.0941|50.651,13.1469
{
"results": [
{
"dataset": "eudem25m",
"elevation": 192.93936157226562,
"location": {
"lat": 50.7827,
"lng": 6.0941
}
},
{
"dataset": "eudem25m",
"elevation": 635.0579833984375,
"location": {
"lat": 50.651,
"lng": 13.1469
}
}
],
"status": "OK"
}
import pandas as pd
import requests
# assuming you have lat/long coords in a DataFrame, maybe from geopandas
coords = pd.DataFrame([[53.66, 13.84],
[51.71, 13.76],
[48.75, 13.76],
[53.95, 13.81],
[50.94, 13.75]],
columns=['lat', 'long'])
# convert to a string for the request, like '53.66,13.84|51.71,13.76|...'
coords_str = coords.to_string(col_space=1, index=False, header=False)
coords_str = ",".join(coords_str.replace('\n', '|').split())
# query Open Topo Data using post request
url = "https://api.opentopodata.org/v1/eudem25m"
req_data = {"locations": coords_str, "interpolation": "bilinear"}
r = requests.post(url, data=req_data)
results = r.json()['results']
# add elevations to DataFrame
elevations = [res['elevation'] for res in results]
coords['elevations'] = elevations
print(coords)
输出:
lat long elevations
0 53.66 13.84 4.061932
1 51.71 13.76 144.021271
2 48.75 13.76 692.658936
3 53.95 13.81 23.207273
4 50.94 13.75 249.106003
results = []
for i, coords in tqdm(all_coords.groupby(all_coords.index // 100)):
coords_str = ...
...
results += r.json()['results']