Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
3a54eeb7
Commit
3a54eeb7
authored
Jul 22, 2024
by
Eric Duminil
Browse files
Displaying Wurzburg open data trees on map
parent
4ed3f015
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
python_scripts/parse_wurzburg_open_data/output/wuerzburg_trees.html
0 → 100644
View file @
3a54eeb7
This diff is collapsed.
Click to expand it.
python_scripts/parse_wurzburg_open_data/parse_open_data.py
View file @
3a54eeb7
...
...
@@ -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."
)
python_scripts/parse_wurzburg_open_data/requirements.txt
View file @
3a54eeb7
...
...
@@ -2,3 +2,4 @@ pandas
requests
fastparquet
folium
rich
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment