Relation

From OpenStreetMap Wiki
Jump to navigation Jump to search
Osm element relation.svg

A relation is a group of elements. In more technical terms, it is one of the core data elements and consists of one or more tags and an ordered list of one or more nodes, ways and/or relations as members which is used to define logical or geographic relationships between other elements. A member of a relation can optionally have a role which describes the part that a particular feature plays within a relation.

Usage

Relations are used to model logical (and usually local) or geographic relationships between objects. They are not designed to hold loosely associated but widely spread items. It would be inappropriate, for instance, to use a relation to group 'All footpaths in East Anglia'.

Size

It is recommended to use not more than about 300 members per relation. Reason: The more members are stuffed into a single relation, the harder it is to handle, the easier it breaks, the easier conflicts can show up and the more resources it consumes on the database and server. If you have to handle more than that amount, some recommend creating several relations and combining them in a Super-Relation (a good concept on paper but software support is poor)

Roles

A role is an optional textual field describing the function of a member of the relation. For example, in a multipolygon relation, role inner and role outer are used to specify whether a way forms the inner or outer part of that polygon. In some countries, role east can indicate that a way carries only the eastbound lanes of a route, as an alternative to a separate relation representing the eastbound route direction.

Types of relation relation

Main article: Types of relation

Multipolygon

Multipolygons are one of two methods to represent area areas in OpenStreetMap. While most areas are represented as a single closed way closed way, almost all area features can also be mapped using multipolygon relations. This is needed when the area needs to exclude inner rings (holes), has multiple outer areas (exclaves), or uses more than ~2000 nodes.

In the multipolygon relation, the role inner and role outer roles are used to specify whether a member way forms the inner or outer part of that polygon enclosing an area. For example, an inner way could define an island in a lake (which is mapped as relation).

Bus route

Each variation of a bus route itinerary is represented by a relation with type=route, route=bus and ref=* and operator=* tags. The first members in the route relation are the nodes representing the stops. These are ordered in the way the vehicles travel along them. Then the ways are added. In PT v2 the ways form an ordered sequence, along the stop nodes. The ways don't get roles. If they form a continuous sequence this is apparent from the continuous line along them (in JOSM's relation editor).

Other Examples

Tools

Navigation on relations

OSRM and Valhalla can use certain route relation roles to influence guidance instructions when a route represents both directions of travel.

For example, some bicycle routers prefer to route on roads with existing bicycle route (as indicator of cycling usability). An application may also follow a pilgrimage=* route relation or, more generally, try to route along the minimum number of numbered road routes.


OSM XML

Main article: OSM XML
 <relation id="56688" user="kmvar" uid="56190" visible="true" version="28" changeset="6947637" timestamp="2011-01-12T14:23:49Z">
  <member type="node" ref="294942404" role=""/>
  ...
  <member type="node" ref="364933006" role=""/>
  <member type="way" ref="4579143" role=""/>
  ...
  <member type="node" ref="249673494" role=""/>
  <tag k="name" v="Küstenbus Linie 123"/>
  <tag k="network" v="VVW"/>
  <tag k="operator" v="Regionalverkehr Küste"/>
  <tag k="ref" v="123"/>
  <tag k="route" v="bus"/>
  <tag k="type" v="route"/>
 </relation>

See also