How are shared boundary ways organised?

Hi, I am doing processing of relations, ways and nodes for administration boundaries to work out which relations border each other. My algorithm uses an assumption and I’d welcome some feedback on whether this assumption is correct.

Say there is a boundary admin level 2 running east-west. Country A is to the north and country B is to the south. The relations will share a way.

If I now zoom in and look at a relation in country A of admin level 12 that also borders country B is it true that:

  • There is a shared way between the country A admin level 12 relation and the country B admin level 2 relation
  • The extent of the shared way is just the extent of the shared border
  • The border between country A and country B is actually divided into lots of short ways to accomodate all the relations of different admin levels on each side of the border

Or is it that the ways that make up the country A admin level 12 relation can join with the country level shared way at nodes anywhere along its length?

I am really hoping it is the former. Hope this question makes sense.
Best, Chessel

Generally, the shared borders of administrative areas are broken into ways that start and end at the points where the borders diverge, but there is no official rule about this (The wiki page for boundary relations contains a lot of can and may, but little must). It’s certainly possible that the border of Country A is represented by a different way that merely overlaps a boundary way of Country B. An administrative area doesn’t need to use a relation at all; if it is simple and small, it can be represented by a single way. You’ll also need to decide whether you consider Utah and New Mexico as “sharing a border,” as they only meet at a single point.

The overall design philosophy of OSM is to make life as easy as possible for map editors; instead of imposing a host of rules, any reasonable approach for representing features is acceptable. On the flip side, this imposes extra complexity on data consumers. The best approach is usually to use a library that does all this heavy lifting and allows you to work with higher-level concepts, such as polygons and spatial predicates.

If that is not an option for you, a possible approach is to track the coordinates of the nodes of each administrative area (You could use a hashtable to map coordinates to areas). You would still need to determine if area A is inside or outside of area B (You would need to assemble an area polygon, then perform a point-in-polygon test). This could likely be avoided by consulting the admin_level tag – if you are looking only for areas at the same level (e.g. country or state), candidate areas are guaranteed to lie outside the test area.

In theory, areas could touch at points that are not nodes, i.e. points that lie on the segment of a way, but such constructs are discouraged in OSM (connected features should be fully noded), so you’re unlikely to encounter them.

Hi, thanks for this reply. Sounds like my assumption is broadly safe but far from guaranteed. I’ll proceed like this for now and see how far it gets me.

Didn’t realise that a single way could be a boundary. In the ISO3166-1:GB area there are 51,000 ways with a boundary=administrative tag in though this does reduce quite a bit if there has to be a name tag also. Lots of islets and rivers in there. Don’t quite understand why rivers are in there but I’ll leave that for now.

Yes, those 4 states that meet at a point do raise the question. I am going for the option that they are bordering at the moment unless this causes complications.

I also think it a more common sense approach to say admin levels can border all admin levels. My user may be looking at a small district and reasonably want to know it is on the border with another country.

Thanks