原文链接,欢迎关注一点规划从杜甫草堂到三圣花乡| ArcGIS与高德地图路径规划APIhttps://mp.weixin.qq.com/s/9Q6GF_4bqv_uw75hdExLyQ
高德API
申请自己的key
https://lbs.amap.com/
创建新应用-选Web服务
路径规划说明:
https://lbs.amap.com/api/webservice/guide/api/newroute
运行
只需要把url中的key换成自己申请的即可,本次是以步行来示例
od.txt为起始点坐标,可以输入多个od点获得多条路径
od_result.txt是输出的拐点结果,需要进arcgis转线
'''
this demo based on Gaode API to plan the route
'''
import json
from urllib import request
line=open('od.txt').read().splitlines() #the load is the demo's load
#to create the api,and u need to apply the key,to choose your ways,the example for walking
url='https://restapi.amap.com/v3/direction/walking?&origin={0}&destination={1}&key=bb0048d866e0ab8da2592490ad65202f'
pts=[] #create the variable to save the point of route
order=1 #order to arcgis
for dis in line:
origin=dis.split(';')[0] #origin point
destination = dis.split(';')[1] #destination point
html = request.urlopen(url.format(origin,destination)).read()
js = json.loads(html)
duration=0
steps=js['route']['paths'][0]['steps']
dis=js['route']['paths'][0]['distance']
for s in steps:
duration=duration+int(s['duration']) #caculate the time
for i in s['polyline'].split(';'):
pts.append(str(order)+','+i) #get the point of route
order+=1
output=open('od_result.txt','w') #load to save
output.write('order,x,y,d,time\n') #the header
for pt in pts:
output.write(pt+',{0},{1}\n'.format(dis,duration)) #write your txt
将result.txt添加进来显示xy坐标,坐标是高德坐标系,加载高德地图在线底图
通过[点集转线工具]转为线要素,这样便得出步行路径
拾取坐标都没注意,还没到三圣乡的嘛
但是它是匹配高德地图的,下面天地图底图的话就偏了,需要纠偏转换坐标(蓝色线)