最近看了一份人民大学的报告,《中国城市政商关系排行榜2020》,https://new.qq.com/omn/20201230/20201230A0F3MY00.html。
讲的是中国各个城市的政商关系健康指数,决定拿这份报告中的数据,来做一份html的专题图。
数据是使用python脚本从腾讯地图webapi上获取的,前端页面使用的是高德地图瓦片。
效果如下:
一、数据获取
参考腾讯web api:https://lbs.qq.com/service/webService/webServiceGuide/webServiceDistrict
脚本:
import requests
import time
# 获取省code和省name列表
def getAllProvince(key):
url = 'http://apis.map.qq.com/ws/district/v1/list?key='+key
reponse = requests.get(url=url)
reponse.encoding = 'utf-8'
data = reponse.json()
provincelist = []
for r in data['result'][0]:
provincelist.append(r['id']+'\t'+r['name'])
return provincelist
# 获取省围栏
def getProvincePolygon(key,provinceCode):
url = 'https://apis.map.qq.com/ws/district/v1/search?&keyword='+provinceCode+'&key='+key+'&get_polygon=2&max_offset=3000'
print(url)
reponse = requests.get(url=url)
reponse.encoding = 'utf-8'
data = reponse.json()
print(data)
path = data['result'][0][0]['polygon']
polygonlist = []
# 对响应结果进行差分解压,lng lat,lng lat,lng lat|lng lat……格式
for p in path:
print(p)
ringlist = []
pointnum = int(len(p)/2)
for i in range(0,pointnum):
ringlist.append(str(p[i*2])+' '+str(p[i*2+1]))
polygonlist.append('POLYGON(('+','.join(ringlist)+'))')
return polygonlist
key = '腾讯key'
healthlist = {'北京':86.33,'上海':81.84,'天津':62.73,&