[英]Raster: How to get elevation at lat/long using python?
I also posted this question in the GIS section of SO. 我也在SO的GIS部分中发布了这个问题。 As I'm not sure if this rather a 'pure' python question I also ask it here again.
因为我不确定这是否是一个“纯” python问题,所以我也在这里再次询问。
I was wondering if anyone has some experience in getting elevation data from a raster without using ArcGIS , but rather get the information as a python list
or dict
? 我想知道是否有人在不使用ArcGIS的情况下从栅格获取高程数据的经验,而是以python
list
或dict
获取信息?
I get my XY data as a list of tuples. 我以元组列表的形式获取XY数据。
I'd like to loop through the list or pass it to a function or class-method to get the corresponding elevation for the xy-pairs. 我想遍历列表或将其传递给函数或类方法,以获取xy对的相应高度。
I did some research on the topic and the gdal API sounds promising. 我对该主题进行了一些研究, gdal API听起来很有前途。 Can anyone advice me how to go about things, pitfalls, sample code?
谁能建议我如何处理事情,陷阱和示例代码? Other options?
还有其他选择吗?
Thanks for your efforts, LarsVegas 感谢您的努力,LarsVegas
I recommend checking out the Google Elevation API 我建议您检查一下Google Elevation API
It's very straightforward to use: 使用起来非常简单:
http://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&sensor=true_or_false http://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&sensor=true_or_false
{
"results" : [
{
"elevation" : 1608.637939453125,
"location" : {
"lat" : 39.73915360,
"lng" : -104.98470340
},
"resolution" : 4.771975994110107
}
],
"status" : "OK"
}
note that the free version is limited to 2500 requests per day. 请注意,免费版本每天限制为2500个请求。
We used this code to get elevation for a given latitude/longitude (NOTE: we only asked to print the elevation, and the rounded lat and long values). 我们使用此代码来获取给定纬度/经度的海拔高度(注意:我们仅要求打印海拔高度以及四舍五入的经度和纬度值)。
import urllib.request
import json
lati = input("Enter the latitude:")
lngi = input("Enter the longitude:")
# url_params completes the base url with the given latitude and longitude values
ELEVATION_BASE_URL = 'http://maps.googleapis.com/maps/api/elevation/json?'
URL_PARAMS = "locations=%s,%s&sensor=%s" % (lati, lngi, "false")
url=ELEVATION_BASE_URL + URL_PARAMS
with urllib.request.urlopen(url) as f:
response = json.loads(f.read().decode())
status = response["status"]
result = response["results"][0]
print(float(result["elevation"]))
print(float(result["location"]["lat"]))
print(float(result["location"]["lng"]))
Here is the another one nice API that I`v built: https://algorithmia.com/algorithms/Gaploid/Elevation 这是我构建的另一个不错的API: https ://algorithmia.com/algorithms/Gaploid/Elevation
import Algorithmia
input = {
"lat": "50.2111",
"lon": "18.1233"
}
client = Algorithmia.client('YOUR_API_KEY')
algo = client.algo('Gaploid/Elevation/0.3.0')
print algo.pipe(input)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.