用Python进行高德地图地址解析,使用SuperMap iDe
2018-09-15 本文已影响8人
Gerhard_杨光辉
大家应该都在学生时代使用过12306购买过学生票,不知道有没有注意到12306的全国高校数据;
经过分析是一个json 文件 ,URL和数据详情如下。
https://kyfw.12306.cn/otn/userCommon/schoolNames
那么作为一个爱折腾的GISer,我们能做点什么呢?
下面我们就通过高德的地址解析API来分析出各个高校的地址,进而做一张全国高校的分布图。
本次采用Python来调用API解析,下面给出Python代码
#-*- coding:utf-8 -*-
import requests
import json
from requests import exceptions
def geocode(address):
parameters = {'address': address, 's': 'rsv3', 'key': '这里填写你的高德地图token'}
base = 'http://restapi.amap.com/v3/geocode/geo'
response = requests.get(base, parameters)
answer = response.json()
if any(answer['geocodes']):
if any(answer['geocodes'][0]['city']):
if any(answer['geocodes'][0]['district']):
return answer['geocodes'][0]['location'] + "," + answer['geocodes'][0]['province'] + "," + answer['geocodes'][0]['city'] + "," + answer['geocodes'][0]['district']
else:
return answer['geocodes'][0]['location'] + "," + answer['geocodes'][0]['province'] + "," + ","
else:
return answer['geocodes'][0]['location'] + "," + answer['geocodes'][0]['province'] + "," + ","
else:
return ","
url = "https://kyfw.12306.cn/otn/userCommon/schoolNames"
response = requests.get(url)
json_str = response.content.decode()
ret1 = json.loads(json_str)
for data in ret1["data"]:
lonlat = geocode(data["chineseName"])
# print(lonlat)
school = data["chineseName"]+","+lonlat+","+data["simplePin"]+","+data["stationTelecode"]+"\r\n"
print(school)
with open("12306withlonlat.csv", "a+", encoding="utf-8") as f:
f.write(school)
解析完成之后,我们会得到这样的包含有地址和经纬度的csv文件,获取到的csv文件中还是有一部分不能获取到位置信息的,一般都是一些研究所和某些涉密的部门,需要我们对数据进一步的筛选和处理。
地址解析结果
然后我们使用SuperMap iDesktop的属性转点讲这些数据转换为点数据,
image.png
转换教程地址 : http://v.youku.com/v_show/id_XMTQxNjk0ODEzMg==.html?spm=a2hzp.8253869.0.0
底图为摩卡托天地图
热力图
四边形网格
六边形网格 换一个暗色的底图,是不是立马高大上了?
分析的结果清晰的显示,大西北的教育还是比较欠缺啊!!!