分享

ArcGIS与高德地图路径规划API

 风声之家 2021-12-21

 Masami 一点规划 2021-12-07 08:00



申请自己的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 jsonfrom 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 walkingurl='https://restapi.amap.com/v3/direction/walking?&origin={0}&destination={1}&key=请输入自己申请的key'pts=[] #create the variable to save the point of routeorder=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 saveoutput.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坐标,坐标是高德坐标系,加载高德地图在线底图

图片

通过[点集转线工具]转为线要素,这样便得出步行路径

图片

拾取坐标都没注意,还没到三圣乡的嘛

但是它是匹配高德地图的,下面天地图底图的话就偏了,需要纠偏转换坐标(蓝色线)

图片

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多