Querying OpenStreetMap through OverpassTurbo

Introduction

A quick tutorial on using OverpassTurbo to query OpenStreetMap. OT is a frontend to create and display queries to work with servers that support the Overpass API.

Examples will use the newer QL syntax instead of the older, and more complex XML syntax. Use http://overpass-api.de/convert_form.html to convert XML samples into QL.

Syntax

A query has three or four parts:

"The QL syntax is more concise, and is to some extend similar to C-like programming languages. A statement always ends with a semicolon ";". Furthermore, a statement is either:

Query statements consist of the type [node, way, relation] and of at least one clause (eg. ["key"])." http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide

"OpenStreetMap represents physical features on the ground (e.g., roads or buildings) using tags attached to its basic data structures (its nodes, ways, and relations). Each tag describes a geographic attribute of the feature being shown by that specific node, way or relation.

http://wiki.openstreetmap.org/wiki/Map_Features

Forward/backward Recursion

  (r)

  (w)

  (n)

  (br)

  (bw)

  (bn)

  (>)

  (>>)

  (<)

  (<<)

what (where); output?

Why bad?

relation["network"="RER"]["ref"="C"] ({{bbox}});
out body;

Examples

Download all McDonald's in a given area

[out:json][timeout:25];
 
{{geocodeArea:Oxfordshire}}->.searchArea;
 
(
  node[name="McDonald's"][amenity=fast_food](area.searchArea);
  way[name="McDonald's"][amenity=fast_food](area.searchArea);
  relation[name="McDonald's"][amenity=fast_food](area.searchArea); 
);
 
out body;
>;
out skel qt;

Download camp sites in given area

We'll use "out center" to turn polygons (ways) into nodes, for better display in maps:

[out:json][timeout:25];
{{geocodeArea:SomeRegion}}->.searchArea;
 
(
  node["tourism"="camp_site"](area.searchArea);
  way["tourism"="camp_site"](area.searchArea);
  relation["tourism"="camp_site"](area.searchArea);
);
 
out center;

Using two statements to fine-tune location

Search "Gielgen" close to Bonn:

node["name"="Bonn"];
node
  (around:1000)
  ["name"="Gielgen"];
out body;

Finding a whole train route including all stops

http://wiki.openstreetmap.org/wiki/Buses

highway=bus stop

route=bus

[out:json][timeout:25];

(

  relation["route"="bus"]({{bbox}});

);

out body;

>;

out skel qt;

 

http://gis.19327.n5.nabble.com/Plans-lignes-RER-td5835260i20.html

[out:json][timeout:25];

(

  relation["network"="RER"]["ref"="C"]({{bbox}});

);

out body;

>;

out skel qt;

---

[out:json][timeout:25];

(

  relation["network"="RER"]["ref"="C"]({{bbox}});

);

node(r);

out body;

>;

out skel qt;

Finding a bus line anywhere in OSM

Provided it's unique…

relation["network"="VRS"]["ref"="636"];
out body;

Finding all the bus stops in the current view

node ["highway"="bus_stop"] ({{bbox}});
out body;

Finding a relation

[out:json][timeout:25];

(
  relation(1258954)({{bbox}});
);

out body;
>;
out skel qt;

{{style:
node {
        symbol-size:    5;
}
}}

Displaying a line in a printable layout

http://www.overpass-api.de/api/sketch-line?ref=1&network=fr_star&style=wuppertal

http://www.overpass-api.de/api/sketch-line?ref=1&network=fr_star&style=padua

http://www.overpass-api.de/api/sketch-line?network=fr_star&ref=1&operator=&correspondences=&width=1000%C3%A0&height=500&font-size=&force-rows=1&max-cors-per-line=&max-cors-below=&style=

From "Public Transport Line Diagram"

Recursion

Comment utiliser…

  1. (

    );
  2. node(r);
  3. out body;
    >;
    out skel qt;
  4. node(50.745,7.17,50.75,7.18)[highway=bus_stop];out;
  5. node(50.745,7.17,50.75,7.18);way(bn);(._;>;);out;

Nécessaire si l'on a besoin de récupérer tous les éléments d'une relation ou d'un way ("route"?).

(

  >;
);

What does this do?

(
._;
nodes(r);
);

What does this do? Why use ()? What does "<;" do?

(node(51.249,7.148,51.251,7.152);<;); out;

Resources