Overpass API/XAPI Compatibility Layer

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Overpass API/XAPI Compatibility Layer
· Afrikaans · Alemannisch · aragonés · asturianu · azərbaycanca · Bahasa Indonesia · Bahasa Melayu · Bân-lâm-gú · Basa Jawa · Baso Minangkabau · bosanski · brezhoneg · català · čeština · dansk · Deutsch · eesti · English · español · Esperanto · estremeñu · euskara · français · Frysk · Gaeilge · Gàidhlig · galego · Hausa · hrvatski · Igbo · interlingua · Interlingue · isiXhosa · isiZulu · íslenska · italiano · Kiswahili · Kreyòl ayisyen · kréyòl gwadloupéyen · Kurdî · latviešu · Lëtzebuergesch · lietuvių · magyar · Malagasy · Malti · Nederlands · Nedersaksies · norsk bokmål · norsk nynorsk · occitan · Oromoo · oʻzbekcha/ўзбекча · Plattdüütsch · polski · português · português do Brasil · română · shqip · slovenčina · slovenščina · Soomaaliga · suomi · svenska · Tiếng Việt · Türkçe · Vahcuengh · vèneto · Wolof · Yorùbá · Zazaki · српски / srpski · беларуская · български · қазақша · македонски · монгол · русский · тоҷикӣ · українська · Ελληνικά · Հայերեն · ქართული · नेपाली · मराठी · हिन्दी · অসমীয়া · বাংলা · ਪੰਜਾਬੀ · ગુજરાતી · ଓଡ଼ିଆ · தமிழ் · తెలుగు · ಕನ್ನಡ · മലയാളം · සිංහල · ไทย · မြန်မာဘာသာ · ລາວ · ភាសាខ្មែរ · ⵜⴰⵎⴰⵣⵉⵖⵜ · አማርኛ · 한국어 · 日本語 · 中文(简体)‎ · 吴语 · 粵語 · 中文(繁體)‎ · ייִדיש · עברית · اردو · العربية · پښتو · سنڌي · فارسی · ދިވެހިބަސް
Overpass turbo · Overpass API · Language reference · Query examples · Language Guide · Advanced examples · Sparse Editing · FAQ · MapCSS · more: Overpass turbo · Overpass API

XAPI Compatibility Layer

See also: Overpass XAPI query builder (harrywood.co.uk)

As requested on SOTM-EU 2011, Overpass API has got a compability layer for the most common XAPI queries. The base URLs are

http://overpass.osm.rambler.ru/cgi/xapi?

or

http://www.overpass-api.de/api/xapi?

The only substantial differences are that Overpass API does not deliver changeset, user, version and timestamp data by default (unless you want to re-add the data again to the main server, this data is anyway not necessary) and does not return relations that contain downloaded elements.

However, if you want the data to be usable in some tools (e.g. JOSM, Osmosis) you can add [@meta] to your xapi request, and you will get them.

Map call

Both versions of the map call are supported, where the variant with map has slight performance advantages:

http://www.overpass-api.de/api/xapi?map?bbox=7.1,51.2,7.2,51.3

http://www.overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.2,51.3]

The order of the four numbers is left,bottom,right,top.

Tags and Bounding Boxes

For node, way, and relation it is possible to either combine arbitrarly many tag search criteria with exactly one or no value:

http://www.overpass-api.de/api/xapi?node[name=Wuppertal-Barmen]

http://www.overpass-api.de/api/xapi?node[name=Wuppertal-Barmen][railway=halt]

http://www.overpass-api.de/api/xapi?node[name=Wuppertal-Barmen][railway=*]

Or you can take at most one search criteria connecting by or: The following finds any node that has name Wuppertal-Barmen or Wuppertal-Oberbarmen.

http://www.overpass-api.de/api/xapi?node[name=Wuppertal-Barmen|Wuppertal-Oberbarmen]

In the same way, you can combine any of the above possibilities with at most one bounding box:

http://www.overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.2,51.3]

http://www.overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.2,51.3][highway=bus_stop]

http://www.overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.2,51.3][name=Wuppertal-Barmen][railway=halt]

http://www.overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.2,51.3][highway=bus_stop|traffic_signals]

http://www.overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.2,51.3][highway=*]

Ways and relation behave similar: A way or relation belongs to a bounding box, if it has as member a node within the bounding box. Or for relations, if a member way has in turn a node in the bounding box as member.

http://www.overpass-api.de/api/xapi?way[name=Fischertal]

http://www.overpass-api.de/api/xapi?way[name=Südstraße|Fischertal]

http://www.overpass-api.de/api/xapi?way[name=Fischertal][bridge=yes]

http://www.overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.2,51.3]

http://www.overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.2,51.3][name=Südstraße]

http://www.overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.2,51.3][name=Südstraße][bridge=yes]

http://www.overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.2,51.3][name=Südstraße|Weststraße]

http://www.overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.2,51.3][maxspeed=*]

Same story for relations:

http://www.overpass-api.de/api/xapi?relation[ref=603]

http://www.overpass-api.de/api/xapi?relation[ref=603|613]

http://www.overpass-api.de/api/xapi?relation[network=VRR][ref=603]

http://www.overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.2,51.3]

http://www.overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.2,51.3][ref=603]

http://www.overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.2,51.3][network=VRR][ref=603]

http://www.overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.2,51.3][ref=603|613]

http://www.overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.2,51.3][ref=*]

Or also any kind of element:

http://www.overpass-api.de/api/xapi?*[ref=603]

http://www.overpass-api.de/api/xapi?*[ref=603|613]

http://www.overpass-api.de/api/xapi?*[network=VRR][ref=603]

http://www.overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.2,51.3]

http://www.overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.2,51.3][name=Weststraße]

http://www.overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.2,51.3][network=VRR][ref=603]

http://www.overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.2,51.3][ref=603|613]

http://www.overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.2,51.3][ref=*]

Meta Data

You can add the directive [@meta] or the endpoint xapi_meta to any query to obtain also meta data in the results. This takes longer, but will allow you to open the results in JOSM.

http://overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?node[bbox=7.1,51.2,7.25,51.3]


http://overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?way[bbox=7.1,51.2,7.25,51.3]

http://overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?relation[bbox=7.1,51.2,7.25,51.3]

http://overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?*[bbox=7.1,51.2,7.25,51.3]

http://overpass-api.de/api/xapi?node[highway=bus_stop][bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?node[highway=bus_stop][bbox=7.1,51.2,7.25,51.3]

http://overpass-api.de/api/xapi?way[highway=motorway][bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?way[highway=motorway][bbox=7.1,51.2,7.25,51.3]

http://overpass-api.de/api/xapi?relation[route=bus][bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?relation[route=bus][bbox=7.1,51.2,7.25,51.3]

http://overpass-api.de/api/xapi?*[highway=*][bbox=7.1,51.2,7.25,51.3][@meta]
http://overpass-api.de/api/xapi_meta?*[highway=*][bbox=7.1,51.2,7.25,51.3]

You can use [@newer=2011-07-01T00:00:00Z] to restrict the results to elements newer than the given date.

http://overpass-api.de/api/xapi?node[bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?way[bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?relation[bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?node[highway=bus_stop][bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?way[highway=motorway][bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?relation[route=bus][bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

http://overpass-api.de/api/xapi?*[highway=*][bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z]

And you can of course also combine both.

http://overpass-api.de/api/xapi?*[highway=*][bbox=7.1,51.2,7.25,51.3][@newer=2011-07-01T00:00:00Z][@meta]

You can restrict the result to elements touched last by a specific user. In the example, it me Roland Olbricht.

http://overpass-api.de/api/xapi?*[highway=bus_stop][bbox=7.1,51.2,7.25,51.3][@user=Roland Olbricht][@meta]

http://overpass-api.de/api/xapi?*[name=Karlsplatz][highway=bus_stop][@user=Roland Olbricht][@meta]

http://overpass-api.de/api/xapi?*[highway=bus_stop][bbox=7.1,51.2,7.25,51.3][@user=Roland Olbricht][@meta]

Or use instead of the user name the user id. It is my user id in the example, 65282.

http://overpass-api.de/api/xapi?*[highway=bus_stop][bbox=7.1,51.2,7.25,51.3][@uid=65282][@meta]

http://overpass-api.de/api/xapi?*[name=Karlsplatz][highway=bus_stop][@uid=65282][@meta]

http://overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.25,51.3][highway=bus_stop][@uid=65282][@meta]


Migrating from XAPI Compatibility Layer to Overpass XML / QL

Before the introduction of Overpass API, XAPI was the only available query language to get live data from OSM. However, as the expressiveness of its language is somewhat limited, only simple use cases are supported. Over time, its importance has diminished significantly. New users are urged to start looking into Overpass Turbo Wizard instead, which comes with a great UI

Current users of the Overpass API XAPI Compatibility Layer can use the following trick to migrate their XAPI based query to Overpass XML:

Existing Query:

http://overpass-api.de/api/xapi?*[bbox=7.1,51.2,7.25,51.3][highway=bus_stop][@uid=65282][@meta]

Prepend the query string by debug? (right after xapi?):

http://overpass-api.de/api/xapi?debug?*[bbox=7.1,51.2,7.25,51.3][highway=bus_stop][@uid=65282][@meta]

The resulting page will include an Overpass XML representation the query executed by Overpass API:

<query type="node">
  <bbox-query s="51.2" n="51.3" w="7.1" e="7.25"/>
  <has-kv k="highway" v="bus_stop"/>
  <user uid="65282"/>
</query>
<union>
  <item/>
  <query type="way">
    <bbox-query s="51.2" n="51.3" w="7.1" e="7.25"/>
    <has-kv k="highway" v="bus_stop"/>
    <user uid="65282"/>
  </query>
  <recurse type="way-node"/>
</union>
<print mode="meta"/>
<query type="relation">
  <bbox-query s="51.2" n="51.3" w="7.1" e="7.25"/>
  <has-kv k="highway" v="bus_stop"/>
  <user uid="65282"/>
</query>
<print mode="meta"/>