See the code (map.py)
"""
Day 2 · Lines
The prompt: A map challenge classic. Map with lines.
What I'm mapping: (write one sentence here once you've decided)
Run it from the project folder:
python days/02-lines/map.py
It saves map.html next to this file. Then see it on the site with:
python build.py --serve
"""
from pathlib import Path
import folium
import geopandas as gpd
from mapkit import palette as P
from mapkit.folium_style import OSM_DATA_CREDIT, add_basemap, add_credit, style_map
HERE = Path(__file__).parent # this day's folder
DATA = HERE / "data" # put the data files you download in here
m = folium.Map(location=[51.517529617507, -0.11694326581724193], zoom_start=12, tiles=None)
add_basemap(m, "light") # background map: also "light-nolabels", "dark", "osm", "mapbox"
style_map(m) # the site's font + ink-outlined buttons
add_credit(m, OSM_DATA_CREDIT) # the tunnel lines are OpenStreetMap data (ODbL), so credit them on the map
gpd = gpd.read_file(DATA / "tube.geojson")
#print(gpd.describe()) # gives a summary of the numeric columns, does not say much about the text columns.
#print(len(gpd)) #how many gates there are.
#print(gpd.columns) #the names of all 157 columns.
#print(gpd.head()) #the first 5 rows of the data, to see what it looks like.
print(gpd["line"].unique())
for _, row in gpd.iterrows():
folium.PolyLine(
locations=[[coord[1], coord[0]] for coord in row["geometry"].coords],
color=P.TUBE_LINES[row["line"].split(";")[0]],
weight=3,
tooltip=row["name"], # replace with a column that makes sense for your data
popup=f"Line Name: {row['name']}" # replace with a column that makes sense for your data
).add_to(m)
m.save(HERE / "map.html")
print("Saved", HERE / "map.html")