Overpass turbo/Examples

From OpenStreetMap Wiki
Jump to navigation Jump to search
Overpass API logo.svg
edit
Overpass API · Language reference · Language guide · Technical terms · Areas · Query examples · Sparse Editing · Permanent ID · FAQ · more · Web site
Servers status · Versions · Development · Technical design · Installation · XAPI compatibility layer · Public transport sketch lines · Applications · Source code and issues
Overpass turbo · Wizard · Overpass turbo shortcuts · MapCSS stylesheets · Export to GeoJSON · more · Development · Source code and issues · Web site
Overpass Ultra · Examples · Overpass Ultra extensions · MapLibre stylesheets · URL Params · more · Source code and issues · Web site

two merging arrows

It has been proposed that this page or section be merged with Overpass API/Overpass API by Example. (Discuss)

Here are some more Examples of interesting overpass queries.

You can click on the turbo icons (overpass turbo icon) for a direct link of the respective query on overpass turbo.

In order to insert such Overpass turbo links on a page, you can embed the logo image with the desired link by [[{{Overpass turbo logo}}|optional tooltip description|link=http://overpass-turbo.eu/?Q=...]].

A simple example from taginfo

Taginfo pages such as this one have a button that links to Overpass Turbo. In this case the query is

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“"monitoring:tide_gauge"=* global”
*/
[out:json][timeout:25];
// gather results
(
  // query part for: “"monitoring:tide_gauge"=*”
  node["monitoring:tide_gauge"];
  way["monitoring:tide_gauge"];
  relation["monitoring:tide_gauge"];
);
// print results
out body;
>;
out skel qt;

Things that you might want to do include:

Commenting out "node", "way" or "relation" with "//" if you're not interested in that sort of feature, or combining them into one query by using "nwr" in place of "node".

Adding

({{bbox}})

to the end of the line to only search within the visible area:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“"monitoring:tide_gauge"=* global”
*/
[out:json][timeout:25];
// gather results
(
  // query part for: “"monitoring:tide_gauge"=*”
  nwr["monitoring:tide_gauge"]({{bbox}});
  //way["monitoring:tide_gauge"];
  //relation["monitoring:tide_gauge"];
);
// print results
out body;
>;
out skel qt;

To search for closed ways

Add "(if:is_closed() == 1)" to the query, like this example:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“"monitoring:tide_gauge"=* global”
*/
[out:json][timeout:25];
// gather results
(
  way["highway"](if:is_closed() == 1)({{bbox}});
);
// print results
out body;
>;
out skel qt;

Complete route relation

This returns a complete route relation, in this case the hiking route "Meraner Höhenweg": try it yourself in overpass-turbo

result of this example
<osm-script output="json">
  <query type="relation" into="hr">
    <has-kv k="route" v="hiking"/>
    <has-kv k="name:de" v="Meraner Höhenweg"/>
  </query>
  <union>
    <item set="hr"/>
    <recurse from="hr" type="relation-way" into="hrp"/>
    <recurse from="hr" type="relation-node"/>
  </union>
  <print mode="body" order="quadtile"/>
  <recurse from="hrp" type="way-node"/>
  <print mode="skeleton" order="quadtile"/>
</osm-script>

Part of a (route) relation

This returns only those ways of a (long) route relation that lie in the current map bounding box: try it yourself in overpass-turbo

<osm-script output="json">
  <query type="relation" into="hr">
    <has-kv k="route" v="hiking"/>
    <has-kv k="ref" v="Hanse"/>
    <bbox-query {{bbox}}/>
  </query>
  <query type="way" into="hrp">
    <recurse from="hr" type="relation-way"/>
    <bbox-query {{bbox}}/>
  </query>
  <union>
    <item set="hr"/>
    <item set="hrp"/>
  </union>
  <print mode="body" order="quadtile"/>
  <recurse from="hrp" type="way-node"/>
  <print mode="skeleton" order="quadtile"/>
</osm-script>

Power substations without proper voltage tag

A query that shows all power substations that have a power line 30 meters from them, but don't have the corresponding voltage tag: try it yourself in overpass-turbo

<query type="way" into="400">
	<has-kv k="power" v="line"/>
	<has-kv k="voltage" v="400000"/>
	<bbox-query {{bbox}}/>
</query>
<query type="way" into="345">
	<has-kv k="power" v="line"/>
	<has-kv k="voltage" v="345000"/>
	<bbox-query {{bbox}}/>
</query>
<query type="way" into="220">
	<has-kv k="power" v="line"/>
	<has-kv k="voltage" v="220000"/>
	<bbox-query {{bbox}}/>
</query>
<query type="way" into="110">
	<has-kv k="power" v="line"/>
	<has-kv k="voltage" v="110000"/>
	<bbox-query {{bbox}}/>
</query>
<union>
	<query type="way">
		<has-kv k="power" v="station"/>
		<bbox-query {{bbox}}/>
	</query>
	<query type="way">
		<around radius="30" from="400"/>
		<has-kv k="power" regv="sub_station|substation"/>
		<has-kv k="voltage" modv="not" regv="400000"/>
		<bbox-query {{bbox}}/>
	</query>
	<query type="way">
		<around radius="30" from="345"/>
		<has-kv k="power" regv="sub_station|substation"/>
		<has-kv k="voltage" modv="not" regv="345000"/>
		<bbox-query {{bbox}}/>
	</query>
	<query type="way">
		<around radius="30" from="220"/>
		<has-kv k="power" regv="sub_station|substation"/>
		<has-kv k="voltage" modv="not" regv="220000"/>
		<bbox-query {{bbox}}/>
	</query>
	<query type="way">
		<around radius="30" from="110"/>
		<has-kv k="power" regv="sub_station|substation"/>
		<has-kv k="voltage" modv="not" regv="110000"/>
		<bbox-query {{bbox}}/>
	</query>
</union>

<union>
	<item/>
	<recurse type="down"/>
</union>
<print/>

Living streets with a potentially wrong speed limit

An example for conflicting (or uncommon) tag combinations: highway=living_street AND maxspeed=30 try it yourself in overpass-turbo (same but simply with all maxspeed=* tags: try it yourself in overpass-turbo) seems to happen quite frequently due to copy & paste errors or re-tagging of "residential" streets. Living streets usually have no but only an untagged implicit speed limit. Of course a living street could really have a 30 km/h speed limit in reality – you should know that location or visit it before changing the tags.

Highways with lanes=1 but no other explaining tag

This example query try it yourself in overpass-turbo searches for highway=*-tagged (only major types) ways with lanes=1 but no other "explaining" tag (junction=roundabout, oneway=*, traffic_calming=*) which may explain why there is only one lane despite these road types being usually 2 lanes. This may be a situation where one of the aforementioned tags may be missing. Be aware: This query will produce false positive hits (correctly mapped objects which still show up in this query)! You may want to adjust the query to e.g. also hit hits when other "explaining" tags are present or to exclude smaller highway types (e.g. unclassified, residential). Note that you should have local knowledge to fix those potential errors, so look at places you know.

Nodes that only have a name tag

This example query try it yourself in overpass-turbo searches for nodes that only have a tag with a name name=* with no other tags (like place=* amenity=*, leisure=*, or shop=*) that would describe the object. This query is useful for finding nodes that need to be properly tagged and this is missing in most QA tools like Osmose.

Bridges without maxweight=...

Example ready to be used in JOSM:

(
  way["bridge"][!"maxweight"]({{bbox}});
); 
(._;>;);
out meta;

Tunnels without maxheight=...

Example ready to be used in JOSM:

(
  way["tunnel"]["tunnel"!~"no"][!"maxheight"][!"waterway"]["highway"!~"steps"]["highway"!~"footway"]["highway"!~"path"]({{bbox}});
); 
(._;>;);
out meta;

include keys with life cycle prefix (regular expression in key)

You can use regular expressions in the key to find tags with life cycle prefix (for example building, amenity, ...)

try it yourself in overpass-turbo
(
  node[~"building"~".*"]({{bbox}});
  way[~"building"~".*"]({{bbox}});
  relation[~"building"~".*"]({{bbox}});
);
out body;
>;
out skel qt;

The search expression for the Overpass Turbo Wizard would be ~"building"~".*"

More