6

有可能的?

我试过:

from geopy.point import Point
from geopy import geocoders
[...]
p = Point(Latitude, Longitude)
lat, lon, altitude = p
height_metres = altitude

但 height_metres 始终为 0。

4

3 回答 3

12

请注意,使用地理编码器,您将需要一个 Google 海拔 API 密钥,该密钥现在需要一个启用计费的项目(截至 2018 年 7 月)。

作为替代方案,您可以使用开放式高程公共 API。这是一个返回海拔的示例函数(注意用于字符串格式化的python 3.6):

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 的一个不错的替代品,抽查表明它运行良好。

于 2018-06-27T14:03:07.803 回答
7

使用地理编码器而不使用geopy是可能的:

# pip install geocoder
>>> import geocoder
>>> g = geocoder.elevation('<address or [lat,lng]>')
>>> print (g.meters)
于 2014-07-16T12:19:44.283 回答
3

I would eat my socks if geopy knew the altitude of every single point on the globe. This isn't possible (afaik) without doing some fancy GoogleEarth/other database searching to figure out the altitude.

The reason why lat, lon, altitude = p works is because the Point has an altitude attribute. According to the source, the only time in the constructor altitude is altered is in the line altitude = float(altitude or 0), which doesn't get the altitude.

于 2013-10-22T09:17:39.537 回答