Overpass turbo is fantastic way to query and export just the data you want from OSM. You can choose to query features with a single OSM tag (e.g. amenity=parking) using the Overpass Turbo Wizard, or you can chose to modify the query into something more complex, such as all amenity features where the key value starts with parking (e.g. amenity=parking and amenity=parking_space). The second example below shows how to query features for a single tag key, such as all the highways. Finally, the last example shows how you can automatically export your features into JOSM, which is a really useful tool if you want features covering a larger area than JOSM will allow you to natively download from the OSM server.
The following is an example I used when I wanted to export parking lots and parking spaces in my neighborhood.
The first query was constructed by using the Wizard tool, where I entered the parking lot tag, which is amenity=parking
<!--
This has been generated by the overpass-turbo wizard.
The original search was:
“amenity=parking”
-->
<osm-script output="json" timeout="25">
<!-- gather results -->
<union>
<!-- query part for: “amenity=parking” -->
<query type="node">
<has-kv k="amenity" v="parking"/>
<bbox-query {{bbox}}/>
</query>
<query type="way">
<has-kv k="amenity" v="parking"/>
<bbox-query {{bbox}}/>
</query>
<query type="relation">
<has-kv k="amenity" v="parking"/>
<bbox-query {{bbox}}/>
</query>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
While this worked great, I was interested in getting two different features returned from my query, specifically I wanted to return both parking lots and individual parking spaces. Parking spaces are rendered currently on the default OSM Mapnik rederer, but their are accepted tagging practices for capturing this information in OSM.
According to the Overpass API language guide, the Overpass API query language supports relative (e.g. non-exact) expressions of locations and names. Since I'd like the query to return records for both parking lots (amenity=parking) and parking spaces (amenity=parking_space), and the value tag for each starts with the word 'parking,' I wanted to see if I could use a wildcard character which would return both values. According to the Language Guide for Non-exact names, to create a query which returns all substring values which start with the work 'parking', you change the value variable name ('v') to 'regv', and add an '^' to the query string.
<!--
This script changes variable name 'v' to 'regv'
and adds a '^' to the beginning of the query string
-->
<osm-script output="json" timeout="25">
<!-- gather results -->
<union>
<!-- query part for: “amenity=parking”
and “amenity=parking_space”
-->
<query type="node">
<has-kv k="amenity" regv="^parking"/>
<bbox-query {{bbox}}/>
</query>
<query type="way">
<has-kv k="amenity" regv="^parking"/>
<bbox-query {{bbox}}/>
</query>
<query type="relation">
<has-kv k="amenity" regv="^parking"/>
<bbox-query {{bbox}}/>
</query>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
When first experimenting with Overpass Turbo, I used the map window extent to define the AOI for my query. However, to get the entire area of my AOI, I was having to include a lot of extra areas of the map that I was not interested in. To narrow the extent of my query, I decided to add a custom AOI to the bbox-query argument.
A helpful tool when you need to quickly get the Lat/Long values for a bounding box is bbox finder. Simply pan and zoom to your area of interest on the interactive map, then draw a polygon around your AOI, and automatically the bounding coordinates will be shown at the bottom of the screen. Be careful to note that the order of the coordinates implies which number defines each side of the bounding box! bbox finder outputs coordinates as: West, South, East, North. According to the Overpass Turbo API Guide though, Overpass Turbo expects the coordinates in the order of : East, North, West, South. I replaced the bounding box argument above (<bbox-query {{bbox}}/>
) with the following: <bbox-query e="-84.335818" n="33.794841" s="33.771085" w=" -84.370322"/>
The following script queries all buildings using the custom bounding box (which generates a large 7MB file).
<osm-script output="json" timeout="25">
<!-- gather results -->
<union>
<!-- query part for: “building= ' '” -->
<query type="node">
<has-kv k="building" modv="" v=""/>
<bbox-query e="-84.335818" n="33.794841" s="33.771085" w=" -84.370322"/>
</query>
<query type="way">
<has-kv k="building" modv="" v=""/>
<bbox-query e="-84.335818" n="33.794841" s="33.771085" w=" -84.370322"/>
</query>
<query type="relation">
<has-kv k="building" modv="" v=""/>
<bbox-query e="-84.335818" n="33.794841" s="33.771085" w=" -84.370322"/>
</query>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
The following query is intended to return all the streets within the Overpass Turbo map window. The query searches for features of type="way" that have key="highway", regardles of whether the tag value is primary, trunk, residential, service, etc.
<osm-script output="json" timeout="25">
<!-- gather results -->
<query type="way">
<has-kv k="highway"/>
<bbox-query {{bbox}}/>
</query>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
This script was generated by clicking the Wizard button at the top of the Overpass Turbo screen and entering "user:[user name]." Since my user name has a space in it, it was necessary to put my user name inside double-quotes.
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“user:"Ryan Lash"”
*/
[out:json][timeout:25];
// gather results
(
// query part for: “user:"Ryan Lash"”
node(user:"Ryan Lash")({{bbox}});
way(user:"Ryan Lash")({{bbox}});
relation(user:"Ryan Lash")({{bbox}});
);
// print results
out body;
>;
out skel qt;
This script was generated by clicking the Wizard button at the top of the Overpass Turbo screen and entering "user:[user name] AND landuse=residential"
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“user:"Ryan Lash" AND landuse=residential”
*/
[out:json][timeout:25];
// gather results
(
// query part for: “user:"Ryan Lash" and landuse=residential”
node(user:"Ryan Lash")["landuse"="residential"]({{bbox}});
way(user:"Ryan Lash")["landuse"="residential"]({{bbox}});
relation(user:"Ryan Lash")["landuse"="residential"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
This script was shared by [email protected] via this post to Humanitarian OpenStreetMap Team listserve
/*
/*replace "4rch" with your username.*/
way["building"]({{bbox}})(user:"Ryan Lash");/*added by auto repair*/(._;>;);/*end of auto repair*/out meta;
You can tell Overpass Turbo to open your returned query results in JOSM if you already have JOSM open and running. To allow JOSM to receive a command from your web-browser, you will need to make certain that you have enabled Remote Control in the JOSM Preferences settings. To double-check this, open JOSM, choose the Edit drop-down menu at the top-left of the screen, and select Preferences (the last item on the drop-down list). The Preferences window will open up, and each of the icons stacked down the left-side of the window will open a different Preference tab. Click on the icon that looks like a remote control emitting a signal (second one up from the bottom). Make sure the "Enable remote control" option button is checked, with all of the additional options checked in the "Permitted actions:" pane.
Now, run a query in Overpass Turbo, and click on Export once the results are returned and displayed. From the Overpass Turbo Export pop-up menu, find "load data into an OSM editor..." and click on the "JOSM" hyperlink. An Incomplete Data error message window will pop-up if in the query command, the print mode is set to 'body' (<Print mode='body'...). For JOSM to open the data, the print mode needs to be set to 'meta'. Fortunately, Overpass Turbo will automatically correct this by clicking on the "repair query" button. Run the query again, and this time when you choose export to JOSM, and the data should automatically load into JOSM.
This features was discovered through the following message board post.