用Python進(jìn)行高德地圖地址解析,使用SuperMap iDesktop 生成中國高校與研究所分布圖

大家應(yīng)該都在學(xué)生時(shí)代使用過12306購買過學(xué)生票,不知道有沒有注意到12306的全國高校數(shù)據(jù);
經(jīng)過分析是一個(gè)json 文件 ,URL和數(shù)據(jù)詳情如下。
https://kyfw.12306.cn/otn/userCommon/schoolNames

12306高校數(shù)據(jù)

那么作為一個(gè)愛折騰的GISer,我們能做點(diǎn)什么呢?
下面我們就通過高德的地址解析API來分析出各個(gè)高校的地址,進(jìn)而做一張全國高校的分布圖。

本次采用Python來調(diào)用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)

解析完成之后,我們會(huì)得到這樣的包含有地址和經(jīng)緯度的csv文件,獲取到的csv文件中還是有一部分不能獲取到位置信息的,一般都是一些研究所和某些涉密的部門,需要我們對數(shù)據(jù)進(jìn)一步的篩選和處理。


地址解析結(jié)果

然后我們使用SuperMap iDesktop的屬性轉(zhuǎn)點(diǎn)講這些數(shù)據(jù)轉(zhuǎn)換為點(diǎn)數(shù)據(jù),


image.png

轉(zhuǎn)換教程地址 : http://v.youku.com/v_show/id_XMTQxNjk0ODEzMg==.html?spm=a2hzp.8253869.0.0
底圖為摩卡托天地圖

點(diǎn)位分布

熱力圖

四邊形網(wǎng)格

六邊形網(wǎng)格

換一個(gè)暗色的底圖,是不是立馬高大上了?

分析的結(jié)果清晰的顯示,大西北的教育還是比較欠缺?。。?!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容