Commit 3a54eeb7 authored by Eric Duminil's avatar Eric Duminil
Browse files

Displaying Wurzburg open data trees on map

parent 4ed3f015
......@@ -9,10 +9,13 @@ from pathlib import Path
import requests
import shutil
import pandas as pd
import folium
from rich import print
SCRIPT_DIR = Path(__file__).resolve().parent
INPUT_DIR = SCRIPT_DIR / 'input'
OUTPUT_DIR = SCRIPT_DIR / 'output'
OUTPUT_DIR.mkdir(exist_ok=True)
INPUT_FILE = INPUT_DIR / 'wuerzburg_trees.parquet'
INPUT_URL = "https://opendata.wuerzburg.de/api/explore/v2.1/catalog/datasets/sls-klimabaeume/exports/parquet?lang=en&timezone=Europe%2FBerlin"
......@@ -34,12 +37,30 @@ else:
df = pd.read_parquet(INPUT_FILE, engine='fastparquet')
print(df)
interesting_columns = ['tree_number', 'species_latin', 'latitude', 'longitude']
interactive_map = folium.Map()
species = 'species_latin'
coordinates = ['latitude', 'longitude']
df[interesting_columns].drop_duplicates().groupby(species).apply(print)
interesting_columns = ['tree_number', 'species_latin', 'latitude', 'longitude']
lat_min, lon_min, lat_max, lon_max = df[coordinates].agg(['min', 'max']).stack().values
interactive_map.fit_bounds([(lat_min, lon_min), (lat_max, lon_max)])
for same, grouped_df in df[interesting_columns].drop_duplicates().groupby(species):
for row in grouped_df.itertuples():
folium.Circle(
location=[row.latitude, row.longitude],
tooltip=row.species_latin,
radius=50, # [m]
color="black",
weight=1,
fill_opacity=0.9,
opacity=1,
fill_color="green",
fill=False, # gets overridden by fill_color
popup=f"Tree #{row.tree_number} ({row.species_latin})",
).add_to(interactive_map)
output_map = OUTPUT_DIR / INPUT_FILE.with_suffix('.html').name
interactive_map.save(output_map)
df[interesting_columns].drop_duplicates().groupby(coordinates).apply(print)
print(f"{output_map} has been written.")
......@@ -2,3 +2,4 @@ pandas
requests
fastparquet
folium
rich
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment