Overpass API/Advanced examples

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Overpass API/Advanced examples
· 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

More complex recursion

Example: Simplest possible map call

This call includes all nodes in the bounding box, all ways that have such a node as member, and all relations that have such a node or such a way as members. Please observe that not all returned ways or relations are displayed in Open Layers because Open Layers requires all nodes of a way or members of a relation to be present.

Overpass XML Overpass QL
try it yourself in overpass-turbo
<osm-script>
  <union into="_">
    <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    <recurse type="up"/>
  </union>
  <print mode="meta"/>
</osm-script>
try it yourself in overpass-turbo
(
  node(50.746,7.154,50.748,7.157);
  <;
);
out meta;

Display result: (Open Layers doesn't show), JSON, XML.

The operator "<" does here all the required backwards resolution of membership links of ways and relations. You could also break this up into step-by-step backwards recursion:

  • First, get all relations linking to the just found nodes: rel(bn);
  • Then, get all ways linking to the just found nodes: way(bn);
  • Finally, get all relations linking to the just found ways: rel(bw);

To complete the list of backwards membership resolution, rel(br); would find relations that have the just found relations as members.

Overpass XML Overpass QL
try it yourself in overpass-turbo
<osm-script>
  <union into="_">
    <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    <recurse into="x" type="node-relation"/>
    <recurse type="node-way"/>
    <recurse type="way-relation"/>
  </union>
  <print mode="meta"/>
</osm-script>
try it yourself in overpass-turbo
(
  node(50.746,7.154,50.748,7.157);
  rel(bn)->.x;
  way(bn);
  rel(bw);
);
out meta;

Display result: (Open Layers doesn't show), JSON, XML.

Completed ways, but not relations

This call includes all nodes in the bounding box, all ways in the bounding box, all member nodes of these ways whether these are inside the bounding box or not, and all relations that have such a node or such a way as members. For the moment, the call of way with a bounding box makes the query sometimes slow. I will work on it, but please be patient for the moment. Please observe that not all returned relations are displayed in Open Layers because Open Layers requires all nodes of a way to be present.

Overpass XML Overpass QL
try it yourself in overpass-turbo
<osm-script>
  <union into="_">
    <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    <recurse into="x" type="node-relation"/>
    <query type="way">
      <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    </query>
    <recurse into="x" type="way-node"/>
    <recurse type="way-relation"/>
  </union>
  <print mode="meta"/>
</osm-script>
try it yourself in overpass-turbo
(
  node(50.746,7.154,50.748,7.157);
  rel(bn)->.x;
  way(50.746,7.154,50.748,7.157);
  node(w)->.x;
  rel(bw);
);
out meta;

Display result: OpenLayers map, JSON, XML.

Completed ways and relations

This call includes all nodes in the bounding box, all ways referring to any of these nodes, all member nodes of these ways whether these are inside the bounding box or not, all relations that have such a node or such a way as a member, and their node and way member, and even the nodes of these ways. Note that due to the involved relations, objects from quite far outside the bounding box are included.

Overpass XML Overpass QL
try it yourself in overpass-turbo
<osm-script>
  <union into="_">
    <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    <recurse type="up"/>
    <recurse type="down"/>
  </union>
  <print limit="" mode="meta" order="id"/>
</osm-script>
try it yourself in overpass-turbo
(
  node(50.746,7.154,50.748,7.157);
  <;
  >;
);
out meta;

Display result: OpenLayers map, JSON, XML.

Here "<" does backwards membership resolution and ">" does forward membership resolution. In particular, ">" collects for all just found relations their member nodes, their member ways, and the member nodes of these member ways. This again can also be broken down into its building blocks:

  • node(w) collects the nodes that are members of the just found ways
  • node(r) does the same with the just found relations
  • way(r) collects the ways that are members of the just found relations

The statement rel(r) collects the relations that are members of the just found relations, but it is not invoked here. Now, the same query as before in a more step-by-step fashion:

Overpass XML Overpass QL
try it yourself in overpass-turbo
<osm-script>
  <union into="_">
    <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    <recurse into="x" type="node-relation"/>
    <recurse type="node-way"/>
    <recurse type="way-relation"/>
  </union>
  <union into="_">
    <item set="_"/>
    <recurse type="relation-way"/>
  </union>
  <union into="_">
    <item set="_"/>
    <recurse into="x" type="relation-node"/>
    <recurse type="way-node"/>
  </union>
  <print mode="meta"/>
</osm-script>
try it yourself in overpass-turbo
(
  node(50.746,7.154,50.748,7.157);
  rel(bn)->.x;
  way(bn);
  rel(bw);
);
(
  ._;
  way(r);
);
(
  ._;
  node(r)->.x;
  node(w);
);
out meta;

Display result: OpenLayers map, JSON, XML.

Also relations on relations

This call includes additionally all relations on relations that after five steps of descent arrive at members in the bounding box. Their members are deliberately not included because that might end up with a significant part of all map data of Germany; i.e., several hundred megabyte of data. Note also that five levels of descent usually is more than enough to get all backlinks. If you doubt you have all backlinks, just add another rel(br); statement and see whether more data comes back.

Overpass XML Overpass QL
try it yourself in overpass-turbo
<osm-script>
  <union into="_">
    <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/>
    <recurse into="x" type="node-relation"/>
    <recurse type="node-way"/>
    <recurse type="way-relation"/>
  </union>
  <union into="_">
    <item set="_"/>
    <recurse type="relation-way"/>
  </union>
  <union into="_">
    <item set="_"/>
    <recurse into="x" type="relation-node"/>
    <recurse type="way-node"/>
  </union>
  <union into="_">
    <item set="_"/>
    <recurse type="relation-backwards"/>
    <recurse type="relation-backwards"/>
    <recurse type="relation-backwards"/>
    <recurse type="relation-backwards"/>
  </union>
  <print mode="meta"/>
</osm-script>
try it yourself in overpass-turbo
(
  node(50.746,7.154,50.748,7.157);
  rel(bn)->.x;
  way(bn);
  rel(bw);
);
(
  ._;
  way(r);
);
(
  ._;
  node(r)->.x;
  node(w);
);
(
  ._;
  rel(br);
  rel(br);
  rel(br);
  rel(br);
);
out meta;

Display result: OpenLayers map, JSON, XML.

Further pages and resources on the openstreetmap wiki