Skip to content

Fixing touching OpenStreetMap polygons

vvoovv edited this page Aug 28, 2025 · 10 revisions

Two helper scripts for working with multipolygons in JOSM:


Installation

Requirements

  • Python 3.8+
  • requests library:
    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

Get an input .osm file

You can use either source below:

  1. From JOSM

    • File → Download from OSM, then File → Save As… (e.g., myarea.osm).
  2. From the Blosm Blender addon

    • When importing with Blosm, an .osm file is written to the folder set in the option Directory to store downloaded OpenStreetMap and terrain files in 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.

Workflow

Step 1 — Complete multipolygon members

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.osm

After it finishes, your active JOSM layer should contain complete multipolygons.


Step 2 — Save updated data

In JOSM, save the layer again (e.g., overwrite myarea.osm) so the file reflects the completed members.


Step 3 — Detect touching polygons

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.osm

JOSM will select the problematic inner ways (only objects present in the active layer can be selected).


Step 4 — Fix in JOSM

One way to resolve the problem of touching polygons is to detouch them:

  1. Select one of the affected polygons together with the shared node. Make sure nothing else is selected.
image
  1. Go to Main menu → Tools → Disconnect node from way.
  2. The selected polygon will get a new edges instead of 2 edges that shared the node in question.
image
  1. 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.

  1. In JOSM, save the layer again (e.g., overwrite myarea.osm).

  2. Run the script josm_select_touching_polygons.pyagain to select remaining touching polygons.

Step 5 — Upload fixes to OpenStreetMap

  1. After making and validating your changes, go to File → Upload data.
  2. Enter a clear changeset comment describing your fix (e.g., “Detouched inner polygons in multipolygon forest relation”).
  3. Upload the changes to the OSM database.

⚠️ Warning: If someone else has edited the same area since you downloaded it, you may encounter upload conflicts. In that case, JOSM will prompt you to resolve the conflicts manually before the upload can proceed.


Summary (Quick Reference)

  1. Complete members:

    python josm_complete_multipolygon_members.py --tag natural=wood --osm-file myarea.osm
  2. Save the layer in JOSM.

  3. Detect touching inners:

    python josm_select_touching_polygons.py --tag natural=wood --osm-file myarea.osm
  4. Fix by detouching

  5. Upload your fix back to the OSM database

Clone this wiki locally