Great, I used python to accurately draw the Beijing Five Rings

How to draw a road route map on the map, taking Beijing Sixth Ring Road as an example, the results are as follows:

image

First of all, the most important thing is that we need to obtain the road coordinate point information, which is composed of a series of coordinate points. Here we rely on the Gaode map to obtain the coordinate information.

Open the AutoNavi map, search for "Five Rings", and use the browser to capture the package to get the road coordinate interface:

image

It can be found that the coordinate data is still relatively hidden, which may also be an anti-climbing measure. Anyway, I found it after looking through it for a long time, and almost wanted to give up.

Then use python code to simulate and obtain coordinate data values:

import requests
import json
import requests
url = "https://www.amap.com/service/poiInfo"
names=['一环','二环','三环','四环','五环','六环']
datas=[]
for name in names:
    querystring = {"query_type":"TQUERY","pagesize":"20","pagenum":"1","qii":"true","cluster_state":"5","need_utd":"true",
                   "utd_sceneid":"1000","div":"PC1000","addr_poi_merge":"true","is_classify":"true","zoom":"10.59","city":"110000",
                   "geoobj":"115.714446|39.806938|117.024755|40.037228","keywords":name}

    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0",
        'Cookie': "cna=C4unE0DWOhkCAW/HM5tXZx6q; isg=BDY2XtDgdVyMNABlY4QxQhMNhGw4V3qR5uyqFKAfIJm049Z9COZtoOOV-zeP0HKp; l=eBPNRte4QBgWGI-jXOfalurza779sIOYYuPzaNbMiOCPs05p5K_AWZJCAZ89Cn1Nh6SwR3yoDYY2BeYBqIYl_XOwsThLxkkmn; tfstk=cFaNB3McbNQZtXg-SVg2cKOWlpHOZ2NgielSjogDD1Ap3fmhi1JxtjhSTj1bKcf..; CNZZDATA1255626299=1693867671-1599310074-https%253A%252F%252Fwww.baidu.com%252F%7C1608342563; _uab_collina=159931078783353165837045; UM_distinctid=17621ccd916b0-0aa3b71503f7838-1a327340-1fa400-17621ccd9174ad; xlly_s=1; x5sec=7b22617365727665723b32223a223536303264653134623164306530663164643861336232393161353761636335434c7a6739663446454d627970376e4f2b706d4d4d513d3d227d; guid=2cf2-47ab-6fb3-87c2",
        }
    response = requests.request("GET", url, headers=headers, params=querystring)
    print(response.text)
    data=json.loads(response.text)['data']['poi_list'][0]['domain_list'][3]['value']
    datas.append(data)

image

The keyword is keywords, replace keywords to get other road coordinate values

In addition, the crawler header information must be added to the cookie value, otherwise the following information will be returned, which also made me entangled for a long time:

  •  
{"rgv587_flag": "sm", "url": "/service/poiInfo/「「tmd」」/punish?x5secdata=5e0c8e1365474455070961b803bd560607b52cabf5960afff39b64ce58073f78f095b6a70f415eb80daf000cedba5ead38d9a2a0ac48b428a68cd31d3048050015ffd60f48a95c19dbd6de3a68e082d35151e037d30b894fa1b9f0617640df860a901a36bd6d324642091753f1253ec47fad7705c7bf26a7ef1aa109e380a620226c7a04348d1829eb44709e59dd96fc56a6252dd094901cf5724d59b1bb3f0850783758416449fc20e5ee69a797df9be0496fd369fe90d5a5cb0968745f36290175faeaa6a5c62f6416f2833375c81943057e2edd1838e1ccc05f4f01cfb61713b9e53b3a344694df999179f2180f7b845ebbb7c256e077889b653f76774fc4ef6a3cd44835da8eebba31e12701f0db05fb79c9eba41a053d0783c4f8755a7ef89354d8b35a2064c031e0aa24dc52ec0e246fc1aadf9a13035d912254a9314098b7da07ac843b06bd0ece7d88ee7766a0c2fc5986066c12006dff7a464dac6c0267bde1e6164d86ade50c3136c9c7bdf90a4a6c568590b4d523216e455515e120dbf7e795ad9f39bda3014f1fd29ab4c04a64f68838a16b73a9e529c48b847da7952539132824d28f7487e8eadc07b2c39d46574c43341bd01587c34986959900dda199ae2b90e2343a9b2118d076c0837c7ece6e8c8ac12a415226e08a1672afd5701786ef448148b53cf33a433555ec5e5da041851c4b0d3ca278a068777113f639debec32ea20c512cf598832f6ae0c9c53c98ea46bef1df79fc778dcd130315fde51df250f3e894c8b965f0040d1cc73da6391ae5d989dbebc98c10d20aa5153bdc7c776e3494d804651bfb8146e26011be062aa3dedbfdf5eaa1990f1acfa677bcca19e4c0f4533607dab59f68204881fc217951995f7bcd2215ae4ace&x5step=2"}
Then integrate the returned data information into a folium applicable format:
results=[]
for data in datas:
    result=[]
    str_data=data.replace('|','_').split('_')
    for i in str_data:
        result.append([float(i.split(',')[1]),float(i.split(',')[0])])
    results.append(result)
results

image

Then use folium for punctuation

import folium
from folium import plugins
map = folium.Map(location=[39.917834, 116.397036], zoom_start=13, zoom_control='False',
               tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',attr='AutoNavi')
incidents = folium.map.FeatureGroup()
for result in results:
    for i in result:
        incidents.add_child(
            folium.CircleMarker(            #CircleMarker表示画圆
                [i[0], i[1]],   #坐标
                radius=7,                   #圆圈半径
                color='purple',             #标志的外圈颜色
                fill=True,                  #是否填充
                fill_color='green',           #填充颜色
                fill_opacity=0.4            #填充透明度
            )
        )

map.add_child(incidents)
map

image

Finally, use folium's PolyLine to connect

import folium
from folium import plugins
map = folium.Map(location=[39.917834, 116.397036], zoom_start=13, zoom_control='False',
               tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',attr='AutoNavi')
incidents = folium.map.FeatureGroup()
for result in results:
    incidents.add_child(
        folium.PolyLine(            #PolyLine用来连线
            result,  
            color='purple'
        )
    )

map.add_child(incidents)
map

image

Summary: With this method, you can do a lot of interesting things, such as drawing a road map, drawing a map of the main roads of the city, etc. Interested friends can study in depth.

 

Here I still want to recommend the Python development exchange learning (qq) group I built by myself : 810735403 , all students in the group are learning Python development. If you are learning Python, you are welcome to join. Everyone is a software development party and share it from time to time. Dry goods (only related to Python software development), including a copy of the latest Python advanced materials and advanced development tutorials compiled by myself in 2021, welcome to advanced and friends who want to go deep into Python!

Guess you like

Origin blog.csdn.net/XIe_0928/article/details/113086215