In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In view of how Python crawls all the electronic eye names in Beijing, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Preface
Today, I would like to share with you a very practical article, using folium to make a traffic surveillance camera distribution map of Beijing, no longer afraid of being secretly photographed by hidden cameras.
The result chart is as follows:
This website can obtain surveillance data from all regions of the country.
Let's take Beijing as an example and use python to crawl all surveillance camera names in Beijing. The code is as follows:
Url1=' https://www.icauto.com.cn/weizhang/wzd/110000/list_1.html'response=requests.get(url1,headers=header)soup=BeautifulSoup(response.text,'html.parser')results=soup.find('div',class_='cdz-ccotent').find_all('li')for result in results: time.sleep (0.5) name=result.find ('a'). Text index=result.find ('span'). Text.split (':) [1]
After packet analysis, the interface for obtaining longitude and latitude information according to the name of surveillance cameras can be obtained:
Https://api.map.baidu.com/?qt=gc&wd= Beijing West Road Zhongba Tunnel Section & cn= Beijing & ie=utf-8&oue=1&fromproduct=jsapi&res=api&ak=s8sS5dBsZ7bLRi3bcVRAaYMAnqlXoyeo
The returned result is:
We mainly look at the coord parameters, just look at it is really a little confused, do not know what this is, I checked for a long time, I know that this is Baidu map using Mercator plane coordinates, using Baidu map api can be converted into longitude and latitude, the conversion code is as follows:
Replace url3=' http://api.map.baidu.com/geoconv/v1/?coords={}&from=6&to=5&ak= with your ak'.format (str (coord ['x']) +','+ str (coord ['y']) response=requests.get (url3,headers=header) result=json.loads (response.text) ['result'] [0] lon=result [' x'] lat=result ['y']
Finally, save the result to the csv table:
With open ('dianziyan.csv',' axioms, newline='', encoding='gb18030') as f: f_csv = csv.writer (f) f_csv.writerow ([name, index, lon,lat])
two。 Punctuation with folium
The method of folium map punctuation has been introduced before, you can refer to:
Python generates the parking lot distribution map of Guangzhou
The code is as follows:
Import pandas as pddata=pd.read_csv ('dianziyan.csv',encoding='gbk') import foliumfrom folium import pluginsCamera_map = folium.Map (location= [data [' latitude'] .mean (), data ['longitude'] .mean ()], zoom_start=10,control_scale=True,) incidents = folium.map.FeatureGroup () for name,row in data.iterrows (): incidents.add_child (folium.CircleMarker (# CircleMarker represents flower circle [row ["latitude]] Row ["longitude"], # coordinates of each parking lot radius=7, # Circle Radius color='yellow', # Outer Circle Color fill=True, # whether to fill fill_color='red', # fill Color fill_opacity=0.4 # fill transparency)) Camera_map.add_child (incidents) Camera_map.save ('Camera_map1.html')
After magnification, it can be found that the coordinate positioning is not very accurate, some seriously deviate from the route, and some are even located in the lake, this is because the base map coordinates and surveillance cameras longitude and latitude standards are not unified.
In order to locate more accurately, we unify the base map and the longitude and latitude of the electronic eye to Amap.
The function of converting Baidu longitude and latitude into Gao de longitude and latitude is as follows:
Import mathdef bdToGaoDe (lat,lon): "" Baidu turns to Gao de longitude and latitude: param lon:: param lat:: return: "" PI = 3.14159265358979324 * 3000.0 / 180.0 x = lon-0.0065 y = lat-0.006 z = math.sqrt (x * x + y * y)-0.00002 * math.sin (y * PI) theta = math.atan2 (y X)-0.000003 * math.cos (x * PI) lon = z * math.cos (theta) lat = z * math.sin (theta) return lat,lon
Read the data and convert it:
Import pandas as pddata=pd.read_csv ('dianziyan.csv',encoding='gbk') for name,row in data.iterrows (): print (bdToGaoDe (row ["latitude"], row ["longitude"])
Change the base image to Amap, and then convert punctuation into surveillance cameras:
Import foliumfrom folium import pluginsCamera_map = folium.Map (location= [data ['latitude'] .mean (), data ['longitude'] .mean ()], zoom_start=10,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 () tooltip = 'Please click on me to view this point information' for name,row in data.iterrows (): incidents.add_child (# CircleMarker for flower circle [bdToGaoDe (row ["latitude"], row ["longitude"]) [0], bdToGaoDe (row ["latitude"], row ["longitude"]) [1] # coordinates of each parking lot icon=folium.Icon (color='green', prefix='fa', icon='bullseye') Camera_map.add_child (incidents) Camera_map.save ('Camera_map2.html')
Through tiles, you can set different map tiles in, here set to Amap tiles
The Folium.Icon class can set the parameters color, icon_color, icon, angle and prefix:
Options for color include: ['red',' blue', 'green',' purple', 'orange',' darkred', 'lightred',' beige', 'darkblue',' darkgreen', 'cadetblue',' darkpurple', 'white',' pink', 'lightblue',' lightgreen', 'gray',' black', 'lightgray'] Or the HTML color code icon_color as above icon can find the corresponding name in the Font-Awesome website and set the prefix parameter to 'fa'angle' in degrees.
It only shows the location of surveillance cameras in Beijing area. Interested friends can make an in-depth study and make a map of the distribution of traffic surveillance cameras across the country.
The answers to the questions about how Python crawls all the electronic eye names in Beijing are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.