This guide describes the procedure for refreshing OpenStreetMap (OSM) highway data for the pipeline. OSM highway data is used for street type risk assessment in the drought risk scoring system.
Since the 2026-04 refactor, the same central loader is used in both places:
street_typescripts/import_osm_highways_to_postgis.pyThe script is therefore now a thin manual wrapper around the pipeline loader, not a separate import implementation.
Recommended Frequency: Annually (October)
Task Type: Data Maintenance
.env file (if not already present):
Copy-Item .env.example .env
.env (if needed):
conda activate bgcki_wesemann
docker ps | grep bgcki-postgis
Uses bounding box from tree inventory data:
python scripts/import_osm_highways_to_postgis.py
Specify a custom geographic area:
python scripts/import_osm_highways_to_postgis.py --bbox "9.5,52.3,10.0,52.5"
Format: "west,south,east,north" (WGS84 coordinates)
Download data without importing to PostGIS (for testing):
python scripts/import_osm_highways_to_postgis.py --dry-run
Ignore cached data and force a fresh download:
python scripts/import_osm_highways_to_postgis.py --force-refresh
The central loader uses intelligent caching to avoid unnecessary downloads:
config.yaml → inputs.roads.refresh_days)data/cache/osm/When running the script or the pipeline again within the cache validity period, the loader automatically uses the existing cache.
After a refresh, verify the data in PostGIS:
-- Total number of imported roads
SELECT COUNT(*) FROM bgcki.context_osm_highways;
-- Distribution of highway types
SELECT highway, COUNT(*)
FROM bgcki.context_osm_highways
GROUP BY highway
ORDER BY COUNT(*) DESC;
-- Geometry information
SELECT
COUNT(*) as total_roads,
ST_GeometryType(geom) as geom_type,
ST_SRID(geom) as srid
FROM bgcki.context_osm_highways
GROUP BY ST_GeometryType(geom), ST_SRID(geom);
Expected results:
ST_LineString25832 (ETRS89 / UTM zone 32N)OSM import settings are configured in config/config.yaml:
inputs:
roads:
source: "osm"
allowed: ["motorway", "trunk", "primary", "secondary", "tertiary", "residential"]
buffer_m: 200.0
refresh_days: 365 # Cache validity in days
timeout_s: 180 # OSM API timeout
| Parameter | Type | Default | Description |
|---|---|---|---|
source |
String | osm |
Data source (OpenStreetMap) |
allowed |
List | See above | Highway types to import |
buffer_m |
Float | 200.0 |
Buffer distance for proximity analysis |
refresh_days |
Integer | 365 |
Cache validity period |
timeout_s |
Integer | 180 |
API request timeout |
Solution:
conda install -c conda-forge osmnx
Possible causes and solutions:
docker ps
docker compose up -d
.env settings (host, port, username, password)Solutions:
inputs:
roads:
timeout_s: 300 # Increase from default 180
python scripts/import_osm_highways_to_postgis.py --bbox "9.7,52.35,9.8,52.4"
Solution:
Verify that PostGIS has the correct spatial reference system:
-- Check if EPSG:25832 is available
SELECT * FROM spatial_ref_sys WHERE srid = 25832;
If missing, the PostGIS installation may need to be updated.
| File/Directory | Purpose |
|---|---|
scripts/import_osm_highways_to_postgis.py |
Import script |
config/config.yaml |
Configuration (see inputs.roads) |
.env |
Database credentials (not in Git!) |
data/cache/osm/ |
Cached OSM data (GPKG format) |
bgcki.context_osm_highways |
PostGIS table (target) |
OpenStreetMap API
↓
osmnx library (Python)
↓
Local cache (GPKG) → 365 days validity
↓
PostGIS database (bgcki.context_osm_highways)
↓
Street type criterion (risk scoring)
The imported OSM highway data is used by the street type criterion in the drought risk scoring system:
For more information, see:
| Date | Version | Changes |
|---|---|---|
| 2025-10-18 | 1.0 | Initial documentation for OSM highway data maintenance procedure |
# Activate environment
conda activate bgcki_wesemann
# Run standard import (uses cached data if valid)
python scripts/import_osm_highways_to_postgis.py
# Verify import
docker exec -it bgcki-postgis psql -U bgcki_admin -d bgcki -c "SELECT COUNT(*) FROM bgcki.context_osm_highways;"
# Force a fresh download (ignore cache)
python scripts/import_osm_highways_to_postgis.py --force-refresh
# This is useful when:
# - OSM data quality has improved
# - Major road network changes occurred
# - Cache is corrupted
# Import data for a specific district using custom bounding box
python scripts/import_osm_highways_to_postgis.py --bbox "9.7,52.35,9.85,52.42"
# Hanover city center example coordinates:
# West: 9.7, South: 52.35, East: 9.85, North: 52.42
For issues or questions: