User:Davetoo/GIS/DataExchange/Polygons

From OpenStreetMap Wiki
Jump to navigation Jump to search

Examples

One outer and one inner ring

The old-style, widely used multipolygon relation allowed only one outer ring and any number of inner rings; rings had to consist of one single closed way only. This type of polygon (not really a multipolygon but more multi-way) is of course still supported but the rules have been relaxed so that this is just a special case of the more general multipolygon relation.
<relation id="1">
  <tag k="type" v="multipolygon" />
  <member type="way" id="1" role="outer" />
  <member type="way" id="2" role="inner" />
</relation>

OGC

  • Figure depicts a single Polygon, with a shell and one hole
  • way #1 is a LinearRing representing the shell of the polygon
  • way #2 is another LinearRing, representing the single hole

Bidirectional conversion should be easy.

Figure 1: One outer and one inner ring

One outer and two inner rings

<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="inner" />
</relation>

OGC

  • Again, and OGS SFS Polygon, this time with two holes
  • way #1 is the shell
  • ways #2 and #3 are the holes

Bidirectional conversion should be easy.

Figure 2: One outer and two inner rings

Multiple ways forming a ring

The advanced multipolygon schema allows any inner or outer ring to consist of more than one way. This is useful for multipolygons encompassing very large areas, where it would be impractical to have one way run around the whole of it:
<relation id="1">
  <tag k="type" v="multipolygon" />
  <member type="way" id="1" role="outer" />
  <member type="way" id="2" role="outer" />
  <member type="way" id="3" role="inner" />
</relation>

OGC

This geometry cannot be represented directly as an OGC SFS Polygon (nor MultiPolygon). The API 0.6 limit of 2000 nodes/way will cause these collections to be created in the case of very large polygons such as shorelines, administrative boundaries, large waterbodies/land areas. OSM-to-OGC translation ideas:

  • The naive method would be to join ways #1 and 2 into a single closed LineString, which then becomes a LinearRing.
    • pro: dead simple
    • con: loses information


Figure 3: Multiple ways forming a ring

Two disjunct outer rings

Unlike old-style multipolygons, the advanced multipolygon relation will also allow any number of outer rings and thus be a true multipolygon:
<relation id="1">
  <tag k="type" v="multipolygon" />
  <member type="way" id="1" role="outer" />
  <member type="way" id="2" role="outer" />
</relation>
Figure 4: Two disjunct outer rings

Two disjunct outer rings and multiple ways forming a ring

The ability to combine a ring from individual ways is not limited to outer rings, it can also be used for inner rings:
<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="inner" />
  <member type="way" id="4" role="outer" />
  <member type="way" id="5" role="inner" />
</relation>
Figure 5: Two disjunct outer rings and multiple ways forming a ring

Complex combination of all advanced features

This example shows a complex combination of all advanced features: three outer rings, two of which have one or more inner rings, and plenty of them consisting of more than one way.
<relation id="1">
  <tag k="type" v="multipolygon" />
  <member type="way" id="1" role="outer" />
  <member type="way" id="2" role="outer" />
  <member type="way" id="3" role="outer" />
  <member type="way" id="4" role="outer" />
  <member type="way" id="5" role="inner" />
  <member type="way" id="6" role="inner" />
  <member type="way" id="7" role="inner" />
  <member type="way" id="8" role="inner" />
  <member type="way" id="9" role="inner" />
  <member type="way" id="10" role="inner" />
  <member type="way" id="11" role="inner" />
  <member type="way" id="12" role="outer" />
  <member type="way" id="13" role="outer" />
  <member type="way" id="14" role="outer" />
  <member type="way" id="15" role="outer" />
  <member type="way" id="16" role="inner" />
  <member type="way" id="17" role="inner" />
  <member type="way" id="18" role="inner" />
  <member type="way" id="19" role="inner" />
  <member type="way" id="20" role="outer" />
</relation>
Figure 6: Complex combination of all advanced features

Island within a hole

From the possibility of having multiple outer rings in one relation, it also follows that you can easily model "islands" within a hole:
<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>

A construct like this would previously have required different multipolygon relations, one with way 1 being outer and way 2 being inner, as well as one with way 2 being outer and way 3 being innner. Such cascading is still recommended when the "island" in the middle is something else than the area on the outside, but where the "island" is the same stuff it can just be made a hole in the hole.

Figure 7: Island within a hole

Touching inner rings

Some mappers use the current "multipolygon" relation for combining touching inner or outer rings:
<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="inner" />
</relation>

An implementation of advanced multipolygons should attempt to render these as if the touching rings were indeed one ring. This is the one case where OpenStreetMap use deviates from standard OGC Simple Features. In Simple Features, touching inner rings are not supported because they are unnecessary. In OpenStreetMap, they sometimes make sense if tagged individually, for example a forest with a clearing which is half occupied by a lake and half by farmland - you would have two "holes" in the forest, one being tagged as natural=water and the other as landuse=farmland. This is a convenience shortcut; requiring of mappers to create only one hole in the forest, and then create individual polygons for lake and farmland, would create too much work for them.

Figure 8: Touching inner rings

Holes in holes (in holes...)

It is possible to have holes in the holes of a multipolygon (think: A forest with a clearing, but a patch of trees in the middle of the clearing).
Example pending.

This is achieved, in compliance with the OGC Simple Features specification, by alternatingly creating outer and inner rings; in our example, the forest outline and the patch of trees would be "outer" rings, and the clearing would be an "inner" ring. This can continue to arbitrary depths but it is suggested to keep complexity down for the benefit of other mappers.

Having holes in holes is also something that may not be supported by all editors and renderers.

Illustration pending.