Create lines instead of markers whenever necessary
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user