The
query statement is so important that, unlike other
statements, it does not have an associated keyword, rather, a query statement is formulated with one of the following specifiers:
-
way
-
node
-
relation
(or rel
for short)
-
area
-
derived
Filters
Types of filters:
Tag | […] |
Identity | (n) , (id: p, q, r …) - (n , p , q , r ) being an id of a node, way or relation) |
Bounding box | (south, west, north, east) |
Around | (around…) |
Polygon | (poly: '…') |
Area (which differ from member filters in that member filters look for relation-node-way parent-child relations while an area filter restricts the selected node to an area) | |
Pivot, which selects the objects (of the chosen type) that enclose an area | way(pivot) , node(pivot) , rel(pivot) , rel(pivot.areaname) etc. |
Member (recursion) | (w) , (r) , (bn) , (br) , r:"x" , r.input:"x" … |
Date | (newer: …) , (changed: …) |
User | user:"franz joseph" , (uid: u) |
Conditional | (if: <evaluator>) |
Tag filter
A tag filter selects objects where certain conditions about their tags are met:
node [ 'key-name' ] // Object has a tag named key-name
node [ ! 'key-name' ] // does not have a tag named key-name
node [ 'key-name' = 'val' ] // The value of object's tag key-name is val
node [ 'key-name' != 'val' ] // The object has the tag key-name and its value is not val OR the object does not have the tag key-name
node [ 'key-name' ~ 're-pattern' ] // The value of tag key-name matches the regular expression re-pattern
node [ 'key-name' !~ 're-pattern' ] // key-name does not match re-pattern
node [ ~ 'key-name-pattern' ~ 're-pattern' ] // Both, the key name and its values are matched with regular expression.
node [ ~ 'key-name-pattern' ~ 're-pattern', i] // Match case insensitively
The following query matches anything whose tag (irrespective of the key) contains historic (case insenstively)
[bbox: {{bbox}} ];
nwr [ ~ '.' ~ 'historic' , i];
out geom;
Combining multiple filters:
node
[name = 'Freienstein'] // There are multiple nodes whose name is 'Freienstein'
[natural = 'peak' ] // So add another filter to find the peak with that name.
;
out;
The following example searches for «highways» in Pfungen whose name contains at least one space:
{{geocodeArea: Pfungen }};
way
[highway]
[name ~ '\\s']
(area);
out geom;
Restrict query to a given area
Find via ferratas in the Canary Islands:
area[ 'ISO3166-2' = 'ES-CN' ];
nwr[highway=via_ferrata](area);
out geom;
around
The around
filter finds elements that are located within a specified radius from a given set of objects: (around[.input_set]:radius)
or from a given longitude/latitude (around:radius,latitude,longitude)
.
Find (hopefully public) toilets within 1 km around the Coop supermarket Zürich Gutstrasse:
node
[shop = supermarket ]
[operator ='Coop Genossenschaft']
[branch ='Zürich Gutstrasse' ];
node
[amenity = toilets]
(around: 1000);
out;
Find consulates within 5 km of Dubrovnik:
node[name=Dubrovnik][place=city];
node(around:5000)[consulate];
out;
node(around: 5, 51.4773352, -0.0008708);
out;
if
node[name='Freienstein']
would find the node ids 240076086, 768109726, 3396807384, 3959626511, 4907345714, 7945522503.
With the conditional if
filter, nodes can be filter with respect to their ids.
[out:csv(
::id,
// ::type,
// "name";
true ; // header (true is default)
";" // separator
)];
node[name='Freienstein']
(if: id() > 4000000000)
// (if: id() % 2) // Apparently, the modulo operator is not supported with Overpass API.
;
out;
The following example uses t[…]
to find nodes in Switzerland whose ele
value is greater than 4000 (meters):
{{geocodeArea:Switzerland}};
node // Search nodes
[ele] // that have an ele tag.
(area) // Restrict search to selected area (geocodeArea)
(if: t['ele'] > 4000 ); // Keep only those nodes whose ele value is greater than 4000
out geom;
Select within a bounding box
node (
49.8727, -6.4458, // minimum latitude and longitude (South and West border)
49.8730, -6.4452 // maximum latitude and longitude (North and East border)
);
out count;
Select within a polygon
The following query selects all nodes in a triangle whose corners are listed in the coordinate pairs listed in the parameter-string:
node(poly:"
50.7 7.14
50.7 7.16
50.71 7.15" // Note: string can apparently not end in new line!
);
out;
Unlike around
, the poly filter doesn't allow to specify «dynamic» values from a previous step in the query.
way(r), node(w) etc.
relation // Select a relation
[waterway = river]
[name ='Töss'];
way (r); // Select ways of selected relation
node(w); // Select nodes of selected ways
out; //'Print' nodes
pivot
area[name = Pfungen ];
rel(pivot);
out geom;
Same result, but with a named area:
area[name = Pfungen ] -> .pfungen;
rel(pivot.pfungen);
out geom;
Date
Find buildinges (nodes and ways) that were modified since August 1st 2022:
[bbox: {{bbox}} ];
nw[building](newer: '2022-08-01T00:00:00');
out geom;
is_in
The railway station Pfungen is in a building which
is in the municipality of Pfungen which
is in the Bezirk of Wintherthur which
is in the Canton of Zurich which
is in Switzerland.
node
[railway = station ]
[name = Pfungen ] -> .pfungen;
.pfungen is_in -> .containers;
.containers out geom;
rel(pivot.containers);
out geom;
Note is_in
returns areas, hence the pivot
statement (operator?).
TODO
Select objects by their id
Select some nodes (that are located in Göbekli Tepe):
node(id:
5789439045,
6080941359,
7572828436,
7572828437
);
out;
Similarly, select ways by ids:
way(id:
190401848,
611531966,
1013140396,
1013140397
);
out geom;
It's also possible to select relations by ids with rel(id: …)
and areas with area(id: …)
.
Select nth node in a way
Select first, ninth, second last and last node in a given way:
way(1083461233);
node(w:1, 9, -2, -1);
out geom;
bbox filter(?)
Select all nodes, ways and relations with a building
tag in the bounding box shown in the overpass turbo editor:
nwr
[ building ]
( {{bbox}} );
out geom;