基于经纬度的批量高程查询——python
通常来说,高程数据的获取途径有以下两个: 1、如果有全球/全国DEM数据,可以在arcgis中获取点的value值,即为高程值。 2、在科学上网的前提下,通过谷歌地图右下角可以查询。 本文介绍一个以python为技术手段查询/批量查询的方法:
from urllib.request import urlopen,quote
import requests,csv
import pandas as pd
import json
import time
import random
def get_elevation(lat,long):
query = ('https://api.open-elevation.com/api/v1/lookup'
f'?locations={lat},{long}')
r = requests.get(query).json()
elevation = pd.io.json.json_normalize(r, 'results')['elevation'].values[0]
return elevation
while True:
print('请输入经纬度(先纬度后经度,用回车隔开): ')
lat=input()
long=input()
c=get_elevation(lat,long)
print('通过经纬度查询到的高程为:'+str(c)+'m')
批量查询代码如下:
def get_elevation(lat,long):
query = ('https://api.open-elevation.com/api/v1/lookup'
f'?locations={lat},{long}')
r = requests.get(query).json()
elevation = pd.io.json.json_normalize(r, 'results')['elevation'].values[0]
return elevation
df=pd.read_excel(r'输入excel',index_col=None)
for i in df.index:
addr_dict=get_elevation(df.loc[i,'北纬'],df.loc[i,'东经'])
df.loc[i,'高程']=addr_dict
print(i)
print(df['高程'])
with pd.ExcelWriter(r'输出excel') as writer:
df.to_excel(writer, sheet_name='sheetname')
|