Comparison of Swiss municipality boundaries between official Swisstopo data (swissBOUNDARIES3D) and OpenStreetMap
This repository uses the ideas presented in https://github.com/stalker314314/osm-admin-boundary-conflation and support from Claude.ai, ChatGPT and Google Gemini to produce a report on the matching of the official swisstopo boundaries to the boundaries mapped in OpenStreetMap.
The initial prompts to Claude.ai were:
I have the boundaries of the swiss municipalities in https://data.geo.admin.ch/ch.swisstopo.swissboundaries3d/swissboundaries3d_2025-04/swissboundaries3d_2025-04_2056_5728.gpkg.zip. Help me produce a report on how well these match geographically with the boundaries mapped in OpenStreetMap, preferrably via Overpass Turbo. The boundaries in the geopackage have
bfs_nummer=355, the boundaries in OSM haveswisstopo:BFS_NUMMER=355as a matching ID.
Can you query Overpass in Python, too?
Can you make this all work in a GitHub action?
You can check the latest comparison results, or view the most recent run summary in [the Actions tab]. The latest results are shown as a (searchable) table on http://boundaries.osm.ch/ Historic data is saved as CSV files to the history directory.
- Schedule: Runs daily at 2 AM UTC via a GitHub Action
- Manual Trigger: Can be triggered manually from the Actions tab
- Data Sources:
- Official: Swisstopo SwissBOUNDARIES3D
- Community: OpenStreetMap via Overpass API
The comparison calculates:
- IoU (Intersection over Union): Measures boundary overlap quality (1.0 = perfect match).
- Area Difference: Percentage deviation in total area
- Hausdorff Distance: Maximum distance between boundary points
- Symmetric Difference: Amount of non-overlapping area
# Install dependencies
pip install geopandas shapely pandas requests pyogrio
# Download and extract Swisstopo data
wget https://data.geo.admin.ch/ch.swisstopo.swissboundaries3d/swissboundaries3d_2026-01/swissboundaries3d_2026-01_2056_5728.gpkg.zip
unzip swissboundaries3d*.zip
# Run comparison (use the script from the GitHub Action)
python compare_boundaries.pyoutput/comparison_report.txt: Human-readable summary reportoutput/detailed_results.csv: Per-municipality metrics in CSV format. This file is shown at the top of the page at http://boundaries.osm.ch/
Contributions are welcome! If you find boundary discrepancies:
- Check the detailed results to identify problematic municipalities
- Verify the boundaries in OpenStreetMap
- Improve OSM data if needed using JOSM or iD editor
- The next automated run will reflect your improvements
Boundaries are matched using:
- Swisstopo:
bfs_nummerfield (official BFS municipality number) - OpenStreetMap:
swisstopo:BFS_NUMMERtag
Data sources:
- Swisstopo data: Terms of Use
- OpenStreetMap data: ODbL