Overpass API/XAPI Compatibility Layer

From OpenStreetMap Wiki
Jump to navigation Jump to search
Overpass API logo.svg
edit
Overpass API · Language reference · Language guide · Technical terms · Areas · Query examples · Sparse Editing · Permanent ID · FAQ · more · Web site
Servers status · Versions · Development · Technical design · Installation · XAPI compatibility layer · Public transport sketch lines · Applications · Source code and issues
Overpass turbo · Wizard · Overpass turbo shortcuts · MapCSS stylesheets · Export to GeoJSON · more · Development · Source code and issues · Web site
Overpass Ultra · Examples · Overpass Ultra extensions · MapLibre stylesheets · URL Params · more · Source code and issues · Web site


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

https://overpass.openstreetmap.ru/cgi/xapi?

or

https://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:

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

https://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:

https://www.overpass-api.de/api/xapi?map?bbox=left,bottom,right,top

  • left is the longitude of the left (westernmost) side of the bounding box, or minlon.
  • bottom is the latitude of the bottom (southernmost) side of the bounding box, or minlat.
  • right is the longitude of the right (easternmost) side of the bounding box, or maxlon.
  • top is the latitude of the top (northernmost) side of the bounding box, or maxlat.


Example for /api/map endpoint - this endpoint is used on the main OpenStreetMap page under "Export" as well.

https://overpass-api.de/api/map?bbox=7.04717,50.95702,7.05125,50.95856

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:

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

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

https://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.

https://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:

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

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

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

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

https://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.

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

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

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

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

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

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

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

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

Same story for relations:

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

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

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

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

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

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

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

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

Or also any kind of element:

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

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

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

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

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

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

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

https://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.

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


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

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

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

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

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

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

https://overpass-api.de/api/xapi?*[highway=*][bbox=7.1,51.2,7.25,51.3][@meta]
https://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.

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

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

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

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

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

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

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

https://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.

https://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.

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

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

https://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.

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

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

https://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:

https://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?):

https://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"/>