NOTICE: help.openstreetmap.org is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum

# Multipolygon in OSM

 1 Hi, I'm developing a Java program to work with OSM data. I'm having big troubles to handle multipolygons due to the fact that the ways that make them up are not ordered and often the roles (outer / inner) are incorrect, so I'm looking for a way to build multipolygons that is not based on roles. I should be able, given all the roads, to rebuild the individual polygons that make up the multipolygon, but how do I know which of these polygons are contained in the other? I'm going crazy, any help is more than appreciated. Thanks! asked 02 Apr '17, 14:15 CillaLu 31●3●3●5 accept rate: 0% "and often the roles (outer / inner) are incorrect" Can you show examples of multipolygons with incorrect roles? Almost always roles should be correct. Maybe you are misinterpreting something? (02 Apr '17, 14:20) scai ♦ I don't understand "given all the roads" - maybe it's a typing error? (02 Apr '17, 14:20) SomeoneElse ♦ I'm not saying that I found errors in the roles but I read that it is possible and I won't take the risk. But let's assume that the roles are correct, looking at this example: Now I ordered them correctly, but the order is not always guaranteed. Assuming the members are not ordered, how do I build the multipolygon? (02 Apr '17, 15:04) CillaLu I meant "given all the ways" instead of "given all the roads". With ways i mean multipolygon relation's members. (02 Apr '17, 15:08) CillaLu

 4 Use this algorithm described in our Wiki: http://wiki.openstreetmap.org/wiki/Relation:multipolygon/Algorithm - it works without looking at the roles. answered 02 Apr '17, 19:16 Frederik Ramm ♦ 82.5k●92●720●1273 accept rate: 23% Frederik, there is though one problem with this (similar) algorithm. If for any reasons a polygonal line (essentially meant to present an outer border section) should be dropped, then the whole multipolygon must be dropped. Otherwise, the polygons (essentially meant to be holes in the ignored outer polygon) will be inverted and will overwrite everything beneath them. With the rules we still may detect which multipolygon elemts are to be ignored and keep many others. (05 Apr '17, 06:54) sanser
 2 I really think you should not be re-inventing the wheel. There are plenty of open source projects and code bases, also for Java, that can handle reading OSM data. Admittedly, the number of programs that properly handle multipolygons, is less, but nonetheless, there are several well maintained ones out there: answered 02 Apr '17, 14:59 mboeringa 1.5k●2●15●27 accept rate: 9% Thanks for the links. The fact is that I'm doing a thesis on OSM and my thesis advisor asked me to write a java tool to do things with OSM data, so I can not just use other libraries. But nothing prevents me to try to figure out how those libraries manage multipolygons. (02 Apr '17, 16:14) CillaLu 3 I did the implementation in libosmium and it cost me several months of my life. Unless your thesis is about the intricacies of the OSM data model, I wouldn't recommend to do this yourself... (02 Apr '17, 20:38) Jochen Topf
 toggle preview community wiki:

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Question tags:

×483
×362
×132

question asked: 02 Apr '17, 14:15

question was seen: 4,140 times

last updated: 05 Apr '17, 06:54

### Related questions

NOTICE: help.openstreetmap.org is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum