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 |
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 ♦ 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
|
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 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
|
"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?
I don't understand "given all the roads" - maybe it's a typing error?
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: <relation id="1"> <tag k="type" v="multipolygon"/> <member type="way" id="1" role="outer"/> <member type="way" id="2" role="inner"/> <member type="way" id="3" role="outer"/> </relation> Now I ordered them correctly, but the order is not always guaranteed. Assuming the members are not ordered, how do I build the multipolygon?
I meant "given all the ways" instead of "given all the roads". With ways i mean multipolygon relation's members.