简体   繁体   English

栅格:如何使用python获得经纬度的海拔?

[英]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 listdict获取信息?

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"]))

Have a look at altimeter a wrapper for the Google Elevation API 看看高度表是Google Elevation API的包装器

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.

相关问题 使用 Python,是否可以遍历栅格并为每个像素提取纬度/经度坐标? - Using Python, is it possible loop through a raster and extract Lat/Long coordinates for each pixel? 如何将网格化的 csv 温度数据(按纬度/经度)转换为栅格地图? - How to convert gridded csv temperature data (by lat/long) to a raster map? 如何在python中从Lat和Long获得带有关联邮政编码的Dataframe? - How to get Dataframe with associated Zip codes from Lat and Long in python? 作业帮助:Python如何使用long和lat确定推文的来源 - Homework Help: Python how to determine origin of a tweet using long and lat Lat,Lon,使用Python将CSV值转换为栅格地图 - Lat, Lon, Values CSV to Raster Map Using Python 如何在Python中将UTM转换为纬度/经度? - How to convert the UTM to Lat/Long in Python? 如何使用经纬度获取用户当前位置 - How to get user current location with lat and long 从长纬度坐标和高程数据创建 tif 文件 - Create tif file from long lat coordinate and elevation data 如何在python中获取给定点(纬度,经度)的边界框(minx,miny,maxx,maxy)和km距离? - How to get bounding-box (minx, miny, maxx, maxy) for an given point (lat, long) and distance in km in python? Python 3.3.5 - 获取我当前位置的经纬度 - Python 3.3.5 - Get my current location's lat and long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM