How to connect ways in a boundary?

Hi all

I’m writing a simple osm file parser in C++. Right now Im loading all the nodes, ways and relations for a country (I’m getting the files from, and then I’m trying to import some of this information into my own data structures. The first thing I’ve tried is to import relations of type=boundary. For simplicity, I’m ignoring enclaves, so it seems that I should be able to connect the outer ways and form the closed polygon which represents the outer boundary. For instance, get the boundary for Luxemburg.

The problem is, I dont know how to connect the ways in the boundary relation, I’m missing something. A simple concatenation of the points in the ways do not work, as it seems like some ways go clockwise and others anticlockwise, and I end having polygons which are complex, i.e. with self-intersections. Is this the expected behaviour and I should just work harder on the algorithm which connects the ways, or is there an additional piece of data somewhere in the osm file with hints about how to connect the ways in a boundary relation?

Thanks in advance

You should “just” work a little harder on the algo. No data is available somewhere else, it’s all there. But you have to take care of little work around to handle bad/strange/unusual data (self intersecting, missing pieces, recursive relations, etc.)

The Multipolygon (boundary relation do works almost the same) page has a link to a proposed algorithm :

osm2pgsql (c/c++) has code to construct polygons out of relation, maybe that can help


Thanks for the info and the links. I’ll take a look at those links. Already working more on the algorithm but some rings are just still not well formed. Now that i know no extra info is available at the osm file, ill continue working on the algorithm.

Thank you