Overpass API/Permanent ID

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Overpass API/Permanent ID
· Afrikaans · Alemannisch · aragonés · asturianu · azərbaycanca · Bahasa Indonesia · Bahasa Melayu · Bân-lâm-gú · Basa Jawa · Basa Sunda · Baso Minangkabau · bosanski · brezhoneg · català · čeština · corsu · 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 · 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 · Wizard · Overpass turbo shortcuts · MapCSS Overpass API · Language reference · Language guide · Query examples · Advanced examples · Sparse Editing · FAQ more: Overpass turbo · Overpass API

Permanent Links to OSM data

What if you want to link to a specific object in OpenStreetMap? You can but you shouldn't use an object ID, because the OSM IDs may change at any time. This may even happen rather frequently. e.g. if an object is deleted and re-added. Also, every split of a way leaves one half with a different ID than the original way.

The solution is to link to the object with a certain property, usually a certain combination of tags. If a unique object exists, you are redirected to the object's web page at openstreetmap.org. Otherwise, if for example the referred way has been split, a search result page shows all possible objects. As an bonus, you can customize both the link target and the appearance of the result page.

Link to Browse Object

A first example is the oldest German motorway, the A 555. A link to this motorway is for example on the German motorway project page, section A 500 to A 599.

To make linking easy, the link is encapsulated in a template. In the wiki page, just write {{DisplayRoute|network=BAB|ref=A 555}}. If you want to describe a route identified by network and ref, you can just fill the template with the values of your object.

Our second example is another route: on express services of WSW_mobil, the second bus route is linked with {{BrowseRoute|network=VRR|ref=CE 62}} to the browse feature. Here, you don't get first to a search result page, because there is more than one relation with this tags, in fact one per direction.

Search by other criteria

The template DisplayRoute isn't helpful if you want to link something completely different. Thus, we discuss some other examples here.

If you want to link to a town described by its place node, you can use a link of the form [1]. Such a link is encapsulated by the template DisplayPlace.

How can you write a template for your own needs?

  • Figure out what tag or combination of tags identifies your object. Typical situations could be
    • a unique value for a key like name or ref. Use [name="something"] then.
    • a certain value to determine the type of the object, e.g. type=route. Use [type=route].
    • the presence of a certain tag, e.g. place in the last example. Use [place] as identifier.
    • the restriction to a certain bounding box, e.g. between the 50th and 51st latitude and 7th and 8th longitude. Use (50,7,51,8).
  • Now you can assemble the link itself. Based on

you can successively insert the collected identifiers after node:


Ways and relations work similar.

  • The next step is to build a template from this type of links. Consider what you want to have as a parameter. In our example, this is "name". For that reason, we replace the content in quotation marks after name= with { {name|} }, the wiki syntax for a named parameter:

Of course, you can use more than one parameter. They only need different names. Now you need to enclose everything after data= in {{urlencode'' and ''}}.

  • The final step is to insert the template with appropriate values on wiki pages that need them. In our example, this is the phrase {{DisplayPlace|name=Bonn}}.

Now you can create permanent links for any kind of object.

  • Example link in mediawiki (source):
[http://overpass-api.de/api/interpreter?data={{urlencode:[out:custom];rel[type=route][operator="Rhönklub"][name="Hochrhöner"];out;}}&url=http://www.openstreetmap.org/?{{{type}}}={{{id}}}  Hochrhöner hiking trail]
{{DisplayOverpass|query=rel[type=route][operator="Rhönklub"][name="Hochrhöner"]|url=http://www.openstreetmap.org/?{{{type}}}={{{id}}}|text=Hochrhöner hiking trail}}

Hochrhöner hiking trail Hochrhöner hiking trail

One general advice: If you create any new templates suitable for Overpass Queries, please include them in the category Category:Overpass API/Templates so that people can find them and make use of them.

See also