import os
import pandas as pd
df = pd.read_csv(os.path.join("data", "highlight_flight_trajectories.csv"))
Let us take a glance at the data.
Each row represents the trajectory of a flight,
and the last column contains the coordinates of the flight path in GeoJSON
format.
df
Unnamed: 0 | dep | dest | geojson | |
---|---|---|---|---|
0 | 0 | Place_MontpellierMediterranee_Airport | Place_BastiaPoretta_Airport | {"type": "LineString", "coordinates": [[3.9613... |
1 | 1 | Place_Bristol___Lulsgate | Place_TenerifeSur_ReinaSofia_Airport | {"type": "LineString", "coordinates": [[-2.719... |
2 | 2 | Place_Valencia_Manises_Airport | Place_Bucuresti_HenriCoanda_Airport | {"type": "LineString", "coordinates": [[-0.481... |
import folium
m = folium.Map(location=[40, 10], zoom_start=4, control_scale=True, prefer_canvas=True)
def style_function(feature):
return {"fillColor": "#ffaf00", "color": "blue", "weight": 1.5, "dashArray": "5, 5"}
def highlight_function(feature):
return {"fillColor": "#ffaf00", "color": "green", "weight": 3, "dashArray": "5, 5"}
for index, row in df.iterrows():
c = folium.GeoJson(
row["geojson"],
name=("{}{}".format(row["dep"], row["dest"])),
overlay=True,
style_function=style_function,
highlight_function=highlight_function,
)
folium.Popup("{}\n{}".format(row["dep"], row["dest"])).add_to(c)
c.add_to(m)
folium.LayerControl().add_to(m)
m