Created
July 23, 2018 09:30
-
-
Save Phyks/44f12147f5cb82024c1f7da6b710d1db to your computer and use it in GitHub Desktop.
Accidents vélos à Montrouge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load from https://opendata.hauts-de-seine.fr/explore/dataset/accidents-corporels-de-la-circulation-routiere/information/?disjunctive.cat_route1&sort=-date&location=18,48.81793,2.3158&basemap=jawg.streets | |
import json | |
import folium | |
import pandas | |
data = pandas.read_csv('accidents-corporels-de-la-circulation-routiere.csv', delimiter=';', parse_dates=['DATE']) | |
map = folium.Map(location=[48.816, 2.321], zoom_start=15, | |
tiles='https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png', attr='toto') | |
for year in sorted(data['DATE'].dt.to_period('A').unique()): | |
bnh_df = data[data['DATE'].dt.to_period('A') == year][data['NB_VEL_BNH'] > 0][data['CODE_INSEE'] == 92049] | |
bh_df = data[data['DATE'].dt.to_period('A') == year][data['NB_VEL_BH'] > 0][data['CODE_INSEE'] == 92049] | |
print(year, len(bnh_df), len(bh_df)) | |
feature_group = folium.FeatureGroup(name='%s' % year) | |
for id, item in bnh_df.iterrows(): | |
point = json.loads(item['geo_shape']) | |
feature_group.add_child( | |
folium.Marker( | |
[point['coordinates'][1], point['coordinates'][0]], | |
popup=( | |
'%s %s' % | |
( | |
item['DATE'].date(), | |
item['HEURE'] | |
) | |
), | |
icon=folium.Icon(color='orange') | |
) | |
) | |
for id, item in bh_df.iterrows(): | |
point = json.loads(item['geo_shape']) | |
feature_group.add_child( | |
folium.Marker( | |
[point['coordinates'][1], point['coordinates'][0]], | |
popup=( | |
'%s %s' % | |
( | |
item['DATE'].date(), | |
item['HEURE'] | |
) | |
), | |
icon=folium.Icon(color='red') | |
) | |
) | |
map.add_child(feature_group) | |
map.add_child(folium.map.LayerControl()) | |
map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment