Use the high-tech map api to draw the isochronous circle of bus + subway

The isochronous circle refers to the range covered by the distance that can be reached in a certain time by a certain mode of transportation from a certain point, which is very common in accessibility analysis. Originally, we needed to rasterize the map and constantly call the path planning api to obtain the isochrone. Now there are websites that have done this for us, such as https://docs.mapbox.com/playground/isochrone/ . We only need to choose the mode of transportation (walking, cycling, and driving) and the time that needs to be drawn, but unfortunately it is impossible to obtain the isochronous circle of the bus (metro/metro + bus).

If we want to obtain the isochronous circle of the bus (subway/bus+subway), what is an easier way? ——> You can use the bus arrival circle function of AutoNavi Map API.

1. Search for the bus arrival circle through the AutoNavi Map API and click to select it.

2. At this time, we can get the time circle of the bus (metro/bus+metro) you want by changing the duration and travel mode.

3. But if you want to put this graph in arcgis/qgis for operation, you need to grab the polygon. We can open the developer tools and find such a link in Network. The outer in the polylines is actually the circle.

4. Grabbing through python.

4.1 First find its url, the key in it needs to be registered in the AutoNavi Map API (the service platform here selects the web (JS API)), and it is parsed through the python requests library.


import json
url = 'https://restapi.amap.com/v3/direction/reachcircle?key=您的密钥&location=116.397428,39.90923&time=44&s=rsv3&extensions=all&output=json&strategy=2&callback=jsonp_488528_&platform=JS&logversion=2.0&appname=https%3A%2F%2Flbs.amap.com%2Fapi%2Fjavascript-api%2Fexample%2Fbus-info%2Farrival-range%2F&csid=73E0636A-636C-43C3-A098-5E94A75837C1&sdkversion=1.4.15'
r  = requests.get(url)
r.text

4.2 Analyze the data. The data obtained is not completely in json format, and it needs some processing. Delete'jsonp_488528_(',')', then convert it to json format, and take out the data in outer.

5. Convert to Polygon

5.1 Convert the latitude and longitude into a dataframe (here I only took two outer tests)

import pandas as pd
test = polylines[0]['outer'].split(';')
lng=[]
lat=[]
for item in test:
    lng.append(item.split(',')[0])
    lat.append(item.split(',')[1])
a = {'lng':lng,'lat':lat}
df = pd.DataFrame(a)

test = polylines[1]['outer'].split(';')
lng1=[]
lat1=[]
for item in test:
    lng1.append(item.split(',')[0])
    lat1.append(item.split(',')[1])
a1 = {'lng':lng1,'lat':lat1}
df1 = pd.DataFrame(a1)

 

5.2 Use Polygon and geopandas to convert into shp files.

import geopandas
from shapely.geometry import Polygon
p0 = Polygon(df.values)
p1 = Polygon(df1.values)
p = geopandas.GeoSeries([p0,p1])
p.to_file('test.json',encoding='utf-8-sig')

 

Guess you like

Origin blog.csdn.net/weixin_42724039/article/details/109755461