Create lines instead of markers whenever necessary

This commit is contained in:
coolneng 2020-06-15 02:05:45 +02:00
parent 3af0605449
commit bb610f3935
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 21 additions and 5 deletions

View File

@ -1,4 +1,4 @@
from folium import Map, Marker from folium import Map, Marker, PolyLine
from pandas import DataFrame, json_normalize from pandas import DataFrame, json_normalize
from app.data_request import request_dataset from app.data_request import request_dataset
@ -15,12 +15,24 @@ def create_dataframe(dataset) -> DataFrame:
return filtered_df 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): 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(): for index, row in df.iterrows():
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"] lng, lat = row["fields.geo_shape.coordinates"]
Marker(location=[lat, lng]).add_to(m) Marker(location=[lat, lng]).add_to(m)
m.save("app/templates/map.html") m.save("app/templates/map.html")

View File

@ -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={}" FLICKR_URL = "https://www.flickr.com/search/?text={}"
COLUMNS = { COLUMNS = {
"deconfinement-pistes-cyclables-temporaires": [ "deconfinement-pistes-cyclables-temporaires": [
"fields.geo_shape.type",
"fields.geo_shape.coordinates", "fields.geo_shape.coordinates",
"fields.statut", "fields.statut",
"record_timestamp", "record_timestamp",
@ -17,12 +18,14 @@ COLUMNS = {
"fields.societe", "fields.societe",
"fields.nb_places_dispositif_environ", "fields.nb_places_dispositif_environ",
"fields.parcs", "fields.parcs",
"fields.geo_shape.type",
"fields.geo_shape.coordinates", "fields.geo_shape.coordinates",
"fields.cp", "fields.cp",
"fields.ville", "fields.ville",
"fields.adresse", "fields.adresse",
], ],
"coronavirus-commercants-parisiens-livraison-a-domicile": [ "coronavirus-commercants-parisiens-livraison-a-domicile": [
"fields.geo_shape.type",
"fields.geo_shape.coordinates", "fields.geo_shape.coordinates",
"fields.adresse", "fields.adresse",
"fields.code_postal", "fields.code_postal",
@ -35,6 +38,7 @@ COLUMNS = {
"fields.mail", "fields.mail",
], ],
"deconfinement-rues-amenagees-pour-pietons": [ "deconfinement-rues-amenagees-pour-pietons": [
"fields.geo_shape.type",
"fields.geo_shape.coordinates", "fields.geo_shape.coordinates",
"fields.nom_voie", "fields.nom_voie",
"fields.categorie", "fields.categorie",