Relation

From OpenStreetMap Wiki
(Redirected from Roles)
Jump to navigation Jump to search
Osm element relation.svg

Relations are structured collections of objects – nodes, ways and other relations. Along with nodes and ways, they are one of the three core data elements of the OpenStreetMap data model.

A relation element must have at least the type=* tag, and a group of members which is an ordered list of one or more nodes, ways and/or relations. It is used to define logical or geographic relationships between these different objects (for example a lake and its island, or several roads forming a bus route). A member of a relation can optionally have a role, describing the function that it plays within a relation. Tags describing the collection as a whole should go only on the relation (e.g. wikidata=*, destination=*, ...), except for the name, if any, which should go in the relation members, too.

As of March 2024, OpenStreetMap contains over 12 million relations.

information sign

On tag description pages, multipolygons are treated as areas area rather than relations relation, since the same tags apply to both closed ways and multipolygons. See FAQ.

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 of England'. See Relations are not categories.

The most common, simple relations contain only members of geometric types (nodes or ways). Relations may also contain other (child) relations, in which case they are informally called "super-relations". It is not usual for a relation to contain both geometric members and child relations, but it is not forbidden.

To be useful, a relation tree should eventually contain geometric members; otherwise, it would be basically invisible, because it is not attached to anything concrete on the map. An empty relation is permitted to exist in the database, but it is not very useful, except maybe as a placeholder for a future expansion. iD editor automatically deletes empty relations obtained by removing members, since they are in most cases inadvertent.

Size

There is a technical limit of 32,000 elements in a relation. It is recommended not to use more than about 300 members per relation: 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).

However, having large relations is sometimes inevitable. For example, boundary relation for Russia, the largest country in the world, has over 4500 ways as outer members.

Roles Osm element role.svg

A role is an optional textual field describing the function of a member in the relation.

For example, in a multipolygon relation, Role outer and Role inner are used to specify whether a way forms an outer or an inner part of that multipolygon.

For a waterway relation of a river (a relation with all the waterway=river of the river and optionally of its tributaries), main_stream on a way will indicate that this is the main part of the river while side_stream is for a branch which will come back in the main stream.

Examples of relation 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 outer and Role inner roles are used to specify whether a member way forms an outer or an inner part of that area.

For example, for a lake with an island, you will map this as a multipolygon with 2 ways, one way (with no tags) with the role "outer" for the outer border of the lake and one way with the role "inner" for the island (which could have some tags like natural=bare_rock if the island is a rocky area).

Bus route

Each variation of a bus route itinerary is represented by a relation with type=route, route=bus and some recommended tags like name=*, ref=*, from=*, to=* and operator=*.

The first members in the route relation are the nodes representing the stops with the role 'stop'. These are ordered in the way the vehicles travel along them. Then the ways are added and will form an ordered sequence along the stop nodes. The ways don't get roles.

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="13092746" visible="true" version="7" changeset="118825758" timestamp="2022-03-23T15:05:48Z" user="" uid="">
  <member type="node" ref="5690770815" role="stop"/>
  <member type="node" ref="5751940550" role="stop"/>
  ...
  <member type="node" ref="1764649495" role="stop"/>
  <member type="way" ref="96562914" role=""/>
  ...
  <member type="way" ref="928474550" role=""/>
  <tag k="from" v="Encre"/>
  <tag k="name" v="9-Montagnes de Guyane"/>
  <tag k="network" v="Agglo'bus"/>
  <tag k="not:network:wikidata" v="Q3537943"/>
  <tag k="operator" v="CACL"/>
  <tag k="ref" v="9"/>
  <tag k="route" v="bus"/>
  <tag k="source" v="https://www.cacl-guyane.fr/wp-content/uploads/2021/01/PLAN-RESEAU-URBAIN-AGGLO-BUS-1.pdf"/>
  <tag k="to" v="Lycée Balata"/>
  <tag k="type" v="route"/>
  <tag k="website" v="https://www.cacl-guyane.fr/lagglo-au-quotidien/se-deplacer/transport-urbain-2/"/>
 </relation>

See also