Files
pupmap/scripts/overlay/roads2-geojson-generate.py
2025-10-03 22:48:16 +01:00

24 lines
653 B
Python

import geopandas as gpd
# Load roads shapefile
gdf = gpd.read_file("/mnt/storage/docker-data/pupmap/www/data/sources/ne_10m_roads.shp")
# Filter by Europe/Nordics bounding box
bbox = (-25.0, 34.0, 35.0, 72.0) # lon_min, lat_min, lon_max, lat_max
gdf = gdf.cx[bbox[0]:bbox[2], bbox[1]:bbox[3]]
# Ensure WGS84 CRS
gdf = gdf.to_crs(epsg=4326)
# Add 'type' property if missing
if 'type' not in gdf.columns:
gdf['type'] = 'road'
else:
gdf['type'] = gdf['type'].fillna('road')
# Save to GeoJSON
gdf.to_file("/mnt/storage/docker-data/pupmap/www/data/roads_europe.geojson", driver="GeoJSON")
print("Cleaned roads saved to roads_europe.geojson")