Лагатып OpenStreetMap OpenStreetMap

Importing boundaries (admin_level=8) into existing boundaries (admin_level=7)

Апублікавана карыстальнікам Janjko 18 Жнівень 2025 на мове English

I’m importing boundaries in Croatia, and I’m almost done. So I wanted to describe my process so that someone else maybe doesn’t have to rediscover this process. Maybe there is a better one, but I didn’t find it.

Croatia in OpenStreetMap had admin_level=7 borders imported, but the borders were not precise. So my job was to import admin_level=8 into these. I had the data in .osm format, and a license that is compatible. I wanted to keep the history of the old boundaries, so deleting everything and just copying inside wasn’t a choice.

First we need JOSM, and some experience with it. We turn on the Expert Mode in View. We need to install the plugin “utilsplugin2”. Then we go to Map Paint Styles in Preferences, and turn on the “Admin Boundaries” style.

So the process goes like this. In JOSM I open the .osm file with all the admin_level=8 boundaries. Then I download the area where I intend to work, but I use “Download from Overpass API” feature. In it I add the next Overpass query:

[out:xml][timeout:90][bbox:{{bbox}}];
(
relation["boundary"="administrative"];
)-> .adminrelations;
(  .adminrelations;
  way(r);
) -> .ways;
(
  node(w.ways);
)-> .nodes;

way(bn.nodes);
(._;<;); (._;>;);
out meta;

What this query does is it downloads all the boundary relations, and all the ways that are connected to them.

1. Disconnecting

Next step I did was to disconnect all the roads, forests, rivers and anything that is not a boundary from the existing boundaries. I upload that, and later download a cleaner situation.

2. Splitting

Next thing I do is I download one whole admin_level=7 that is disconnected from everything. I am in the OSM layer, and I have the import layer behind. I need to split the admin_level=7 borders so that there is one admin_level=7 border for each admin_level=8 border that outlines it (shortcut for splitting, “p”). Splitting After all the splits are made, I upload it to the server so that each split part gets its OSM id.

3. Copying

Now in the OSM layer select the relation for the admin_level=7 boundary we are importing. Then activate the importing layer. In the background I see the outline of the borders I want to select. Then select at least one way from each of the relations that are inside the admin_level=7 in the background. All the admin_level=8 relations we want to copy should be purple. Now select all the relations in the “Objects” window in the sidebar, right click, and “Select relation”. Now select all the relations in the “Sel.” window, right click and “Select members”. Now go to Selection button in the toolbar, and click “Select way nodes”. Now again like in first step, select ways so that each relation has at least one way selected. Then select all relations in the “Objects” window, right click and “Select relation (add)”. Then select all objects in “Sel.” window, right click and “Select members (add)”. Now select all objects in the “Sel.” window, copy with Ctrl+C. Select the OSM data layer, and paste Edit>”Paste at source position”

4. Conflating

Go to the edge of the pasted boundaries, and they should be pasted over the old boundaries. Each new pasted boundary way should have a corresponding old admin way. We should select both, and “Ctrl-Shift-G”, which is Replace Geometry in More Tools. That should replace the old way that has the OSM id, with the new way that doesn’t have the id. This brings up the dialog where I select to keep all the relations, and change the admin_level to the lower one. If ways are directly one over the other, you can select their nodes, and click “Ctrl-E” which selects ways that contain those nodes. After that, Ctrl-Shift-G.

5. Fixing

After all the whole boundary is done, there will probably be some errors to fix. For example, nodes that are not connected, or some boundaries that weren’t conflated well. Uploading data will run the validator on the changed data first, and will give very helpful errors. Click Cancel and fix the errors. After fixing them, upload data. On to the next one!

Email icon Bluesky Icon Facebook Icon LinkedIn Icon Mastodon Icon Telegram Icon X Icon

Абмеркаванне

Каментар ад Friendly_Ghost у 19 Жнівень 2025 у 15:25

That’s a good workflow. Thank you for the work and the write-up!

Каментар ад Lejun у 21 Жнівень 2025 у 05:28

Any tips about the “disconnecting” part of the process?

Увайсці каб пакінуць каментар