diff --git a/app/preprocessing.py b/app/preprocessing.py index 3fe4348..02295d7 100644 --- a/app/preprocessing.py +++ b/app/preprocessing.py @@ -1,4 +1,4 @@ -from folium import Map, Marker +from folium import Map, Marker, PolyLine from pandas import DataFrame, json_normalize from app.data_request import request_dataset @@ -15,12 +15,24 @@ def create_dataframe(dataset) -> DataFrame: return filtered_df +def reverse_coordinates(row): + """ + Reverses each tuples coordinates to ensure folium can parse them correctly + """ + coord = [tuple(reversed(t)) for t in row["fields.geo_shape.coordinates"]] + return coord + + def create_map(df): """ - Creates a Map with markers from the DataFrame + Creates a Map with markers or lines from the DataFrame """ - m = Map(location=COORDINATES, zoom_start=12) + m = Map(location=COORDINATES, zoom_start=12, tiles="Stamen Terrain") for index, row in df.iterrows(): - lng, lat = row["fields.geo_shape.coordinates"] - Marker(location=[lat, lng]).add_to(m) + if row["fields.geo_shape.type"] == "LineString": + coord = reverse_coordinates(row["fields.geo_shape.coordinates"]) + PolyLine(locations=coord, color="blue", opacity=0.5).add_to(m) + else: + lng, lat = row["fields.geo_shape.coordinates"] + Marker(location=[lat, lng]).add_to(m) m.save("app/templates/map.html") diff --git a/constants.py b/constants.py index aaa1b3f..19345f9 100644 --- a/constants.py +++ b/constants.py @@ -8,6 +8,7 @@ DATASET_URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&r FLICKR_URL = "https://www.flickr.com/search/?text={}" COLUMNS = { "deconfinement-pistes-cyclables-temporaires": [ + "fields.geo_shape.type", "fields.geo_shape.coordinates", "fields.statut", "record_timestamp", @@ -17,12 +18,14 @@ COLUMNS = { "fields.societe", "fields.nb_places_dispositif_environ", "fields.parcs", + "fields.geo_shape.type", "fields.geo_shape.coordinates", "fields.cp", "fields.ville", "fields.adresse", ], "coronavirus-commercants-parisiens-livraison-a-domicile": [ + "fields.geo_shape.type", "fields.geo_shape.coordinates", "fields.adresse", "fields.code_postal", @@ -35,6 +38,7 @@ COLUMNS = { "fields.mail", ], "deconfinement-rues-amenagees-pour-pietons": [ + "fields.geo_shape.type", "fields.geo_shape.coordinates", "fields.nom_voie", "fields.categorie",