Skip to content
Snippets Groups Projects
Commit 880ec9f9 authored by Lejf Diecks's avatar Lejf Diecks
Browse files

Added example 05 - Park bench map Norderstedt

parent b6fab515
No related branches found
No related tags found
No related merge requests found
Showing
with 39548 additions and 0 deletions
Show a map of all park benches in the city of Norderstedt stored in a SHP file.
Source: https://opendata.schleswig-holstein.de/dataset/parkbanke
Source #2 (Geoservice): https://geoservice.norderstedt.de/geoserver/eso/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=eso:parkbank&outputFormat=SHAPE-ZIP
import geopandas as gpd
import pandas as pd
import folium
import zipfile
import os
# Unpack ZIP file containing geodata to subfolder
zip_file_path = 'parkbench.zip'
output_dir = 'shapefile_extracted'
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
zip_ref.extractall(output_dir)
# Locate shapefile in subfolder (suffix SHP) and read it
shp_file = [f for f in os.listdir(output_dir) if f.endswith('.shp')][0]
shp_file_path = os.path.join(output_dir, shp_file)
gdf = gpd.read_file(shp_file_path)
# The folium library can only work on WGS84 (EPSG:4326) coordinates.
# This is not provided by the shape file, but geopands can convert this
# on the fly using the to_crs() method:
print("Shapefile coordinate system before conversion:", gdf.crs)
gdf = gdf.to_crs(epsg=4326)
print("Shapefile coordinate system before conversion:", gdf.crs)
# Show all park bench data in terminal as fromatted table
# If you use the default pandas output settings will only show the first five lines
# and it will remove some data for convenience. We don't want this so we disable some
# of pandas' display settings beforehand:
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_colwidth', None)
pd.set_option('display.expand_frame_repr', False)
pd.set_option('display.max_rows', None)
print(gdf)
# Visualize park benches on a map. Use center of data in shape file as center point
center_lat = gdf.geometry.y.mean()
center_lon = gdf.geometry.x.mean()
# Create OpenStreetMap overlay using folium library
m = folium.Map(location=[center_lat, center_lon], zoom_start=6)
# Add each park bench to overlay
for idx, row in gdf.iterrows():
lat = row.geometry.y
lon = row.geometry.x
ort = row.ort
folium.Marker([lat, lon], popup=f'{ort}').add_to(m)
# Save finished overlay to map
m.save('output.htm')
print("Overlay has been saved to output.htm")
#!/bin/bash
# Install necessary python packages for this example
pip install folium
pip install geopandas
pip install pandas
pip install zipfile
This diff is collapsed.
05_ParkbenchMap/output.png

1.12 MiB

Source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
ISO-8859-1
\ No newline at end of file
File added
PROJCS["ETRS89 / UTM zone 32N", GEOGCS["ETRS89", DATUM["European Terrestrial Reference System 1989", SPHEROID["GRS 1980", 6378137.0, 298.257222101, AUTHORITY["EPSG","7019"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY["EPSG","6258"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4258"]], PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], PARAMETER["central_meridian", 9.0], PARAMETER["latitude_of_origin", 0.0], PARAMETER["scale_factor", 0.9996], PARAMETER["false_easting", 500000.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","25832"]]
\ No newline at end of file
File added
File added
https://geoservice.norderstedt.de/geoserver/eso/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=eso:parkbank&outputFormat=SHAPE-ZIP
\ No newline at end of file
Collection of generic functions to show how to download from Open-Data Schleswig-Holstein (tbd)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment