我可以在Python中使用geopy来获得高度吗?(经度/纬度) [英] Can I get the altitude with geopy in Python? (with Longitude/Latitude)
问题描述
有可能吗?
我尝试过:
from geopy.point import Point
from geopy import geocoders
[...]
p = Point(Latitude, Longitude)
lat, lon, altitude = p
height_metres = altitude
但是height_metres始终为0.
but height_metres is always 0.
推荐答案
请注意,使用地址解析器,您将需要一个Google海拔API密钥,该密钥现在需要启用了结算功能的项目(截至2018年7月).
Note that with geocoder you will need a Google elevation API key which now requires a project with billing enabled (as of July 2018).
或者,您可以使用开放式高程公共API.这是一个返回标高的示例函数(注意python 3.6用于字符串格式化):
As an alternative, you can use the open elevation public API. Here's an example function to return the elevation (Note python 3.6 used for string formatting):
import requests
import pandas as pd
# script for returning elevation from lat, long, based on open elevation data
# which in turn is based on SRTM
def get_elevation(lat, long):
query = ('https://api.open-elevation.com/api/v1/lookup'
f'?locations={lat},{long}')
r = requests.get(query).json() # json object, various ways you can extract value
# one approach is to use pandas json functionality:
elevation = pd.io.json.json_normalize(r, 'results')['elevation'].values[0]
return elevation
请注意,API将来可能会更改,我无法评论数据的准确性,但目前它是Google的不错选择,抽查表明它可以正常工作.
Note, the API may change in the future and I can't comment on veracity of the data but currently it's a nice alternative to Google and spot checks suggest it works fine.
这篇关于我可以在Python中使用geopy来获得高度吗?(经度/纬度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!