OSM Data Structure

OSM Data Structure#

Nodes, Ways, Relations and Tags#

A general overview on the OSM data structure can be found in the OSM Wiki. It is important to get yourself familiar with OSM’s data model, since this will have consequences how to analyse the data. There are three main types of objects in OSM’s data model:

  1. nodes (defining points in space),

  2. ways (defining linear features and area boundaries), and

  3. relations (which are sometimes used to explain how other elements work together).

All of the above can have one or more associated tags (which describe the meaning of a particular element).

“A tag consists of two items, a key and a value. Tags describe specific features of map elements (nodes, ways, or relations) or changesets. Both items are free format text fields, but often represent numeric or other structured items.” - Check this entry in the OSM Wiki for information about tags.

There is no fixed dictionary of tags, but there are many conventions documented on this wiki (starting with the Map Features page). Tag usage can be measured with the taginfo application. If there is more than one way to tag a given feature, it’s probably best to use the most common approach.

We use the term OSM contributor when referring to a user that contributed data to OSM, e.g. by creating a building or editing a highway. Contributors can be identified by their uid. Be aware that the name of an OSM contributor might change over time. So make sure to use the uid attribute when you want to filter to the contributions of a specific contributor.

On the OSM website you can easily explore the data and it’s structure. Just use the query tool and click on the map or enable the “map data” layer.

Quick-Exercise

Go to https://www.openstreetmap.org and search for a place you have recently visited. Use the query tool and check a few OSM objects for this region.

This is an example how the raw OSM data looks like. This node contains several tags and has been edited six times already. Each tag is described by a key (k) and value (v), e.g. <tag k="office" v="research"/>. Often we will use the following syntax to describe this less technically office=research. The last user who edited this OSM object was 1222061 (current name Joker234).

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.8.8 (70891 spike-08.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
 <node id="4540889804" visible="true" version="6" changeset="74474248" timestamp="2019-09-14T13:54:37Z" user="Joker234" uid="1222061" lat="49.4184793" lon="8.6756824">
  <tag k="addr:city" v="Heidelberg"/>
  <tag k="addr:housenumber" v="45"/>
  <tag k="addr:postcode" v="69120"/>
  <tag k="addr:street" v="Berliner Straße"/>
  <tag k="level" v="4"/>
  <tag k="name" v="Heidelberg Institute for Geoinformation Technology"/>
  <tag k="office" v="research"/>
  <tag k="short_name" v="HeiGIT"/>
  <tag k="website" v="https://heigit.org"/>
  <tag k="wheelchair" v="yes"/>
 </node>
</osm>

Here is an example of a way representing a primary street in Heidelberg. You should be familiar with the tag structure already. However, note that this way does not contain any geometry, but only refers to two nodes (<nd ref="270418052"/> and <nd ref="6772131501"/>). Thus, without further information on these nodes, it will not be possible to delineate the geometry of this street. But luckily, most of the OSM tools you will work with, will handle this characteristic of OSM’s data structure for you. You might want to check the latest version of this OSM object here: https://www.openstreetmap.org/way/721933838

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.8.8 (1895549 spike-08.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
 <way id="721933838" visible="true" version="4" changeset="117197083" timestamp="2022-02-09T11:04:52Z" user="fbausch" uid="235962">
  <nd ref="270418052"/>
  <nd ref="6772131501"/>
  <tag k="cycleway" v="separate"/>
  <tag k="highway" v="primary"/>
  <tag k="lanes" v="2"/>
  <tag k="lit" v="yes"/>
  <tag k="maxspeed" v="50"/>
  <tag k="name" v="Berliner Straße"/>
  <tag k="name:etymology:wikidata" v="Q64"/>
  <tag k="oneway" v="yes"/>
  <tag k="priority_road" v="designated"/>
  <tag k="sidewalk" v="separate"/>
  <tag k="surface" v="asphalt"/>
  <tag k="zone:maxspeed" v="DE:urban"/>
  <tag k="zone:traffic" v="DE:urban"/>
 </way>
</osm>

Changesets#

Changesets are another important concept in OSM and can be very useful when filtering OSM data for specific contributors or mapping campaigns. Whenever somebody changes something in the OpenStreetMap database these changes are first bundled into a changeset, similar to how you group changes in a git commit. Again, it’s always useful to check the Wiki.

“A changeset consists of a group of changes made by a single user over a short period of time. One changeset may for example include the additions of new elements to OSM, the addition of new tags to existing elements, changes to tag values of elements, deletion of tags and also deletion of elements.”

This example shows the common metadata available for changesets such as timestamps, bounding box coordinates and user id. Many changesets have a specific comment tag. During mapping campaigns this is often used to provide more information on the purpose of the mapping. But also in general this comment can provide contextual information on the map edits. Further useful information is provided about the mapping software (created_by). Check here for more details: https://www.openstreetmap.org/changeset/124703880

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.8.8 (1985848 spike-07.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
 <changeset id="124703880" created_at="2022-08-09T21:14:57Z" closed_at="2022-08-09T21:14:59Z" open="false" user="DaryaSea" uid="14174743" min_lat="30.3525220" min_lon="48.2833660" max_lat="30.3583001" max_lon="48.2951977" comments_count="0" changes_count="16">
  <tag k="source" v="Bing aerial imagery"/>
  <tag k="hashtags" v="#adt"/>
  <tag k="created_by" v="JOSM/1.5 (18463 en)"/>
  <tag k="comment" v="Adjusted the building geometry ردیف B13 in Khuzestan #adt"/>
 </changeset>
</osm>

Changesets can also be queried by it’s bounding box. This can be useful for geospatial analysis of changesets that cover only a specific area.

Quick-Exercise

Explore the most recent changes in OSM and their location through OSM in Realtime. Click on the changeset comment on the right side and inspect what has been changed in the given changeset.