it is possible?
i tryed:
from geopy.point import Point
from geopy import geocoders
[...]
p = Point(Latitude, Longitude)
lat, lon, altitude = p
height_metres = altitude
but height_metres is always 0.
geopy is a Python client for several popular geocoding web services. geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources.
Geopy is a Python library that simplifies the calculation of geographic distances between two points. It makes it easier for developers to retrieve coordinates of various locations using third-party geocoders, as well as other data sources.
Note that with geocoder you will need a Google elevation API key which now requires a project with billing enabled (as of July 2018).
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
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.
It's possible with geocoder not with geopy:
# pip install geocoder
>>> import geocoder
>>> g = geocoder.elevation('<address or [lat,lng]>')
>>> print (g.meters)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With