Overpass API/Permanent ID

From OpenStreetMap Wiki
Jump to: navigation, search

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. In the context of license change, this even may happen rather frequently. 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 extra, 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
    http://overpass-api.de/api/interpreter?data=[out:custom];node;out;

you can successively insert the collected identifiers after node:

    http://overpass-api.de/api/interpreter?data=[out:custom];node[place][name="Bonn"];out;

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:
    http://overpass-api.de/api/interpreter?data=[out:custom];node[place][name="{{name|}}"];out;

Of course, you can use more than one parameter. They only need different names. Now you need to enclose everything after data= in Template: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]

Sea also

Query-to-map

WIWOSM