(written by AKD with the help of Brian Hollinshead and Heikki Vesanto)

If you are a somewhat experienced mapper or data consumer, you will have heard or read about overpass-turbo.eu, the powerful mining tool for extracting data from OpenStreetMap. And even if you are neither, and especially if you are neither, you might find an answer to your question here.

Basic queries are easily built with the Wizard, and a lot of the basics are covered by the wiki page for overpass-turbo, but sometimes, you want more sophisticated filters and you soon get stuck. Usually, you end up searching online for a solution or asking in our Telegram chat, send an email to the board or ask in the Facebook group. Some of those questions appear again after some time and the queries are adaptable, so here’s a collection of them which you can adapt to your own needs. Most of these were queries built by mappers in Ireland for some reason or other.

Important note: The search results can only be as good as the data provided by contributors like yourself, so wherever the description says “search for all the features”, it means “search for all the features mapped so far”.

(You can replace whatever is in the left window of the overpass-turbo website with any of the examples below and hit “run” to start the query or just use the link provided with each example. Sometimes, you might still have to hit “run”.)

TOC

Counting results

The bottom right corner in the overpass-turbo query gives you a summary of the nodes, ways and relations found in your query. However, if you are looking for, lets say the number of field names, you are not interested in the total number of nodes, because each field is made of several nodes, some might be mapped as relations and some field names* might be added as nodes. To circumvent this, all you need to do is add “center” to the output line. This will find the centre of all the ways and relations and count them under “pois”.

Results for field names in Co. Westmeath
[out:json][timeout:25];
// fetch area “County Westmeath” to search in
{{geocodeArea:County Westmeath}}->.searchArea;
// gather results
nwr["landuse"="farmland"]["name"](area.searchArea);
// print results
out geom center;

Open overpass-turbo query here.
* Some might be landuse=meadow and some might have their old_name mapped as well, so bear that in mind when you’re trying to look for all field names.

Searching for several features at once

If you wanted to add landuse=meadow to to the search above, you can group the two (or more) searches by putting them into round brackets and closing with a semicolon:

Results for farmland & meadows
[out:json][timeout:25];
// fetch area “County Westmeath” to search in
{{geocodeArea:County Westmeath}}->.searchArea;
// gather results
(
nwr["landuse"="farmland"]["name"](area.searchArea);
nwr["landuse"="meadow"]["name"](area.searchArea);
);
// print results
out geom center;

Boundaries

OpenStreetMap Ireland is a great place to get all kinds of data of administrative boundaries, be it townlands, Electoral Divisions, parishes etc. Currently used administrative boundaries are displayed in purple lines on openstreetmap.org, but maybe you want to build your own map with some of the data or you are looking for historic boundaries for genealogical research reasons.

Townlands

Information about townlands as the smallest administrative unit in Ireland are still very sought after by genealogists and others. As you probably know, townlands.ie is dedicated to providing much of that information. But what if you want to retrieve the data of the townlands from just one county

Mapping background: Townlands are mapped as relations and are admin_level=10. You find an overview of the different admin levels on the wiki here.

Here is the link to an overpass-turbo query for the townlands in Co. Offaly and this is what the query looks like:

[out:json][timeout:25];
// fetch area “County Offaly” to search in
{{geocodeArea:County Offaly}}->.searchArea;
// gather results
relation["admin_level"="10"](area.searchArea);
// print results
out geom;
Townlands in Co. Offaly

Maybe you want to look for all the townlands in a barony instead? Then this is the overpass-turbo link with an example for the Galmoy barony and this is the code:

[out:json][timeout:25];
// fetch area “Galmoy” to search in
{{geocodeArea:Ireland}}->.searchArea;
// gather results
(
// query part for: “admin_level=10”
area["name"="Galmoy"]["boundary"="barony"];
rel(area)["admin_level"="10"];
);
// print results
out body;
>;
out skel qt;
Townlands in Galmoy

It may not be required as often, but what if you want to display the townlands within a bounding box (bbox) with their names? The names are displayed using map css. This is what that looks like in overpass:

[out:json][timeout:25];
// gather results
(
  // query part for: “admin_level=10”
  relation["admin_level"="10"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
{{style:
area{text:name;}
}}
Townlands within a bounding box

Census boundaries

At time of writing this, the recent census boundaries have not been made open data (open enough to use on OSM). Microsoft received a waiver and added the census boundaries for 2015/2016 for 1,563 areas which you will find with the key ref:IE:census2015. The project is briefly described on the wiki. Here is the overpass link for the Republic of Ireland, but you can change the area to a county by replacing “Ireland” by “County Laois” (for example) after “geocodeArea:”

[out:json][timeout:25];
// fetch area “Ireland” to search in
{{geocodeArea:Ireland}}->.searchArea;
// gather results
nwr["ref:IE:census2015"](area.searchArea);
// print results
out geom;
Areas with key ref:IE:census2015

Historic census boundaries/ Electoral Divisions

Mapping background: Several historic electoral divisions have been mapped on the island. A lot of work, including parish boundaries, was done by Brian Hollinshead, and the results can be seen on his website.However, since there was no ready-made shapefile to be used for the historic electoral divisions, the areas are based on the results of census data from 1901 and 1911 for each townlands (or streets in cities). This means that if nobody was home in that townland on census day or nobody was living in the townland that year, this townland will not appear in the list and will form a gap in the Electoral Division area on OpenStreetMap. Searching for 1911 census boundaries in Co. Antrim will look like this in overpass:

/* 
Searching for boundary with the date 1911 in County Antrim 
*/
[out:json][timeout:25];
// fetch area “County Antrim” to search in
{{geocodeArea:County Antrim}}->.searchArea;
// gather results
nwr["type"="boundary"]["date"="1911"](area.searchArea);
// print results
out geom;
EDs in Co. Antrim according to 1911 census data

Name searches

Name includes

Show me all pubs that have “Paddy” in their name could be one of those requests. Here would be the overpass-turbo link and this is what the code looks like:

[out:json][timeout:25];
// fetch area “Ireland” to search in
{{geocodeArea:Ireland}}->.searchArea;
// gather results 
nwr["amenity"="pub"]["name"~"Paddy"](area.searchArea);

// print results
out geom;
Search for pubs with “Paddy” in the name, with some map css added to the query

Name ends in

Maybe you are looking for all features whose name ends in a certain word. Show me all the residential highways in Northern Ireland whose name ends in “Lane” would be this overpass-turbo query and this is what the code looks like:

[out:json][timeout:25];
// fetch area “Northern Ireland” to search in
{{geocodeArea:Northern Ireland}}->.searchArea;
// gather results
nwr["highway"="residential"][name~".* Lane"](area.searchArea);
// print results
out geom;
Name Lanes in Northern Ireland

Name starts with

Searching for all residential highways in Northern Ireland starting with “Victoria” is this overpass-turbo link and looks like this:

[out:json][timeout:25];
// fetch area “Northern Ireland” to search in
{{geocodeArea:Northern Ireland}}->.searchArea;
// gather results
nwr["highway"="residential"][name~"Victoria .*"](area.searchArea);
// print results
out geom;
Victorian streets in Northern Ireland

Search within an area using way ID

Every node, way and relation on OpenStreetMap has an ID which you can use to define the search area. Brian Hollinshead has mapped many trees in Dublin with their species, reference numbers etc, and this overpass-turbo query searches for the trees in the Botanical Gardens and displays their reference number using some map css:

[out:json][timeout:25];
// defines area of Botanical Gardens using way ID 16141015 and searches for trees within, displaying their reference
way(16141015);
map_to_area;
nwr["natural"="tree"][ref](area);
out body;
>;
out skel qt;
{{style:
node{text:ref;}
}}
Trees and their reference numbers in the Botanical Gardens

Excluding features from search

There are several reasons to exclude features with a certain tag from a group of similar features, one could be quality insurance (“show all plaques without inscriptions”, so you know where to survey and add inscriptions). This is done by placing an exclamation mark strategically.The following query was used by VictorIE to find townlands in Co. Dublin where the logainm:url lacks the required “http”:

[out:json][timeout:25];
// fetch area “County Dublin” to search in
{{geocodeArea:County Dublin}}->.searchArea;
// gather results
(
  // query part for: “locality=townland and "logainm:url"=* and "logainm:url"!~http”
    relation["locality"="townland"]["logainm:url"]["logainm:url"!~"http"](area.searchArea);
);
// print results
out body;
>;
out skel qt;
Townlands with missing “http” in logainm:url in County Dublin

Geometric searches

Searching for features within a radius of another feature

These are the searches when it gets really interesting and they show the power of OpenStreetMap. In the past, searches like “show me all the banks in the United States with a gun shop within a 100m radius” (or similar) have been food for thought. Another life or death situation could be to show all defibrillators within a 20m radius of a train station. This of course only works for mapped AEDs/ defibrillators which you can easily add using openaedmap.org which is also available as an Android or iOS app. Here is the link to overpass and this is what it looks like. You can easily change the radius, of course.

[out:json][timeout:25];
// fetch area “Ireland” to search in
{{geocodeArea:Ireland}}->.searchArea;
// gather results 
(
way["building"="train_station"](area.searchArea);
relation["building"="train_station"](area.searchArea);  
  );

// find defibs around train stations
node(around:20)["emergency"="defibrillator"](area.searchArea);

// print results
out geom;
Train stations with (mapped!) defibrillators within a 20m radius

Lets say, you’ve been to mass at St. Thérèse’s Church in Mount Merrion, you’re looking for a place in the shade under an oak tree, but afterwards, you want to go to a nearby café with someone you met under the tree (as one does). You can search for that with overpass-turbo thus:

// Search for all the oak trees within a 100m radius and all cafés and bars in a 800m radius from the coordinates 53.29515,-6.20968
[out:json];
(
  node["natural"="tree"]["genus"="Quercus"](around:100,53.295, -6.21);
  node["amenity"~"cafe|bar"](around:800,53.29515,-6.20968);
);
out center;

{{style:
node[natural]
{color:green;fill-color:green;symbol-size:5;}

node[amenity] {
  icon-image: url('icons/maki/cafe-18.png');
  icon-width: 18;
  text:name;
}
}}
Results for running the tree and café query above

Using “value greater than” and similar operators

The following overpass query searches for mountain peaks higher than 800m:

/*
Searching for peaks higher than 800m within bounding box 
*/
[out:json][timeout:25];(
  node[natural=peak]({{bbox}})
      (if:t["ele"] > 800);
);
out;
Peaks above 800m within bounding box

Feature value between two numerical values

Maybe you want to limit the elevation to between 1001 and 1100m instead:

/*
Searching for peaks between 1001m and 1100m elevation within bounding box 
*/
[out:json][timeout:25];
(
  node[natural=peak]({{bbox}})
      (if:t["ele"] > 1001 && t["ele"]<1100);
);
out;
Peaks with elevation between 1001 and 1100m

Highlighting ways in a relation with a certain key

Mapping background: Route relations are consecutive strings of ways in a group (hiking or bus route, similarly waterways which are not routes) without drawing layers of ways on top of one another. The same road, for example, can be part of several administrative boundaries as well as being “just a road”. 

If you wanted to extract only certain ways which are part of that relation, you can use a query like this one:

/*
Searches for the named relation Wild Atlantic Way and displays only the bridges on it (note: waw and x are chosen at random, you can use any string of letters)
*/
[out:json][timeout:25];
// search for relation similar to the name "Wild Atlantic Way" within the bounding box and assign it the ID "waw"
(
relation["name"~"Wild Atlantic Way"]({{bbox}});
)->.waw;
// Get all the ways/nodes that are part of the relation found in the part above, i.e. recurse down and assign new identity "x" to that data
(.waw>;)->.x;
// Extract those ways that have a bridge tag
(way.x[bridge];);
// print results
out body;
>;
out skel qt;

If on the other hand, you wanted to show only certain nodes which are parts of the relation, for example fords along the boundary between the Republic of Ireland and Northern Ireland, you would use this very similar query:

/*
Searches for the border between RoI and NI and displays only the fords along it
*/
[out:json][timeout:25];
// search for relation of the name "Northern Ireland" and assign it the ID "ni"
(
relation["name"~"Northern Ireland"];
)->.ni;
// Get all the ways/nodes that are part of the relation found in the part above, i.e. recurse down and assign new identity "x" to that data
(.ni>;)->.x;
// Extract those nodes that have a ford tag
(node.x[ford];);
// print results
out body;
>;
out skel qt;
(mapped) fords along the border

Other queries

Here is a list of other queries you might find interesting or useful: