为了查看各小区周边的交通是否便利,我们还需要获取轨道交通线路及出入口数据。
获取地铁站和出入口数据,可以使用高德地图的webapi。
获取轨道交通线的数据,直接解析高德地图的页面响应。
一.获取地铁站和出入口数据
把获取小区的脚本改一改,就能获取地铁站及出入口数据了。
步长改的大一些,地铁站一共没有多少个。
import requests
from shapely.geometry import Polygon
from shapely import wkt
from requests.adapters import HTTPAdapter
s = requests.Session()
s.mount('http://', HTTPAdapter(max_retries=3))#设置重试次数为3次
s.mount('https://', HTTPAdapter(max_retries=3))
# 获取矩形搜索到poi的count数量
# key,是高德地图的key
# r是矩形,[minlng,minlat,maxlng,maxlat]
def countSearchPoi(key,r):
minlng = r[0]
minlat = r[1]
maxlng = r[2]
maxlat = r[3]
url = 'https://restapi.amap.com/v3/place/polygon?types=150500&offset=20&page=1&extensions=all&output=json&polygon='\
+ str(minlng) +',' + str(minlat) + '|' + str(maxlng) + ',' + str(maxlat) + '&key=' + key
count = -1
print(url)
try:
r = s.get(url, timeout=5)
data = r.json()
if 'status' in data:
if data['status'] == '1':
count = int(data['count'])
except BaseException as e:
print(e)
return count
# 切分矩形,把大矩形分成四个小矩形
def clipRectangle(r):
minlng = r[0]