-
Notifications
You must be signed in to change notification settings - Fork 212
Fixing touching OpenStreetMap polygons
Two helper scripts for working with multipolygons in JOSM:
-
josm_complete_multipolygon_members.py
Downloads and adds missing members (inner/outer ways) of tagged multipolygon relations to the current JOSM layer. -
josm_select_touching_polygons.py
Detects and selects inner rings that touch each other or touch the outer ring.
- Python 3.8+
-
requestslibrary:pip install requests
- A running JOSM with Remote Control enabled:
- JOSM → Edit → Preferences → Remote Control
- Enable:
- Enable remote control
- Load data from API
- Change the selection
You can use either source below:
-
From JOSM
-
File → Download from OSM, then File → Save As… (e.g.,
myarea.osm).
-
File → Download from OSM, then File → Save As… (e.g.,
-
From the Blosm Blender addon
- When importing with Blosm, an
.osmfile is written to the folder set in the optionDirectory to store downloaded OpenStreetMap and terrain filesin the addon preferences. - The file name corresponds to the imported object’s name in Blender.
- Locate that file and use it as the script input.
- When importing with Blosm, an
Run the script to make sure all members of tagged multipolygons are present in your current JOSM layer.
python josm_complete_multipolygon_members.py --tag natural=wood --osm-file myarea.osmAfter it finishes, your active JOSM layer should contain complete multipolygons.
In JOSM, save the layer again (e.g., overwrite myarea.osm) so the file reflects the completed members.
Run the detector to find inner rings that share nodes with another inner or with the outer polygon, and select them in JOSM.
python josm_select_touching_polygons.py --tag natural=wood --osm-file /path/to/myarea.osmJOSM will select the problematic inner ways (only objects present in the active layer can be selected).
One way to resolve the problem of touching polygons is to detouch them:
- Select one of the affected polygons together with the shared node. Make sure nothing else is selected.
- Go to Main menu → Tools → Disconnect node from way.
- The selected polygon will get a new edges instead of 2 edges that shared the node in question.
- Grab the middle of this new edge and drag it slightly back toward the position of the former shared node.
→ This operation separates the polygons so they no longer share the same node.
-
In JOSM, save the layer again (e.g., overwrite
myarea.osm). -
Run the script
josm_select_touching_polygons.pyagain to select remaining touching polygons.
- After making and validating your changes, go to File → Upload data.
- Enter a clear changeset comment describing your fix (e.g., “Detouched inner polygons in multipolygon forest relation”).
- Upload the changes to the OSM database.
-
Complete members:
python josm_complete_multipolygon_members.py --tag natural=wood --osm-file myarea.osm
-
Save the layer in JOSM.
-
Detect touching inners:
python josm_select_touching_polygons.py --tag natural=wood --osm-file myarea.osm
-
Fix by detouching
-
Upload your fix back to the OSM database