NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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's gravatar image

CillaLu
31335
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: <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?

(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

Use this algorithm described in our Wiki: http://wiki.openstreetmap.org/wiki/Relation:multipolygon/Algorithm - it works without looking at the roles.

permanent link

answered 02 Apr '17, 19:16

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
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

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:

  1. http://wiki.openstreetmap.org/wiki/Osmosis
  2. https://github.com/osmcode/libosmium
  3. https://github.com/osmcode/pyosmium
permanent link

answered 02 Apr '17, 14:59

mboeringa's gravatar image

mboeringa
1.5k21527
accept rate: 9%

edited 02 Apr '17, 15:01

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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,622 times

last updated: 05 Apr '17, 06:54

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum