Okay, let's look up how to search for relations in Overpass Turbo using the Overpass Query Language (QL).
To search for relations in Overpass Turbo, you use the Overpass Query Language (QL).[1] Here's how you can do it:
-
Basic Relation Query:
- To query for any relation within the current map view (bounding box), you use the
relation keyword followed by the bounding box filter ({{bbox}}). You also need an output statement like out geom; or out body;.
relation({{bbox}});
out geom;
```[2]
* `relation` specifies the element type you are looking for.
* `({{bbox}})` is a shortcut in Overpass Turbo that automatically uses the coordinates of the map view you are currently looking at.[2][3]
* `out geom;` tells Overpass to output the full geometry (including nodes and ways that make up the relation) and tags.[2] `out body;` outputs tags and member IDs but not necessarily full geometry unless combined with recursion.[2] `out center;` outputs the center point for relations.[2][4]
-
Filtering by Tags:
- You can filter relations based on their tags using square brackets
[].[2] Tags are key-value pairs used in OpenStreetMap to describe features.[5]
- Example: Find bus routes: Bus routes often use the tag
type=route and route=bus.
relation["type"="route"]["route"="bus"]({{bbox}});
out geom;
```[2]
- Example: Find administrative boundaries: Administrative boundaries often use
boundary=administrative. You might specify an admin_level as well.
relation["boundary"="administrative"]["admin_level"="4"]({{bbox}});
out geom;
```[2] * **Example: Find relations with a specific name:**
```ql
relation["name"="Wild Atlantic Way"]({{bbox}});
out geom;
```[2][6]
- Example: Find relations where a specific tag exists (regardless of value): This finds relations that have the tag "network".
relation["network"]({{bbox}});
out geom;
```[2]
- You can combine multiple tag filters by adding more bracket pairs.
-
Searching by Relation ID:
-
Using the Wizard:
- For simpler queries, you can use the "Wizard" feature in Overpass Turbo.[3][4]
- Type a simple search like
type=route and route=bus or boundary=administrative and the wizard will try to generate the Overpass QL for you.
- The wizard often generates queries for nodes, ways, and relations (
nwr). You might need to edit the generated query to specify only relation if that's all you need.
-
Outputting Members:
- Sometimes you need the ways and nodes that are members of a relation.[3][4]
- The
out geom; statement usually handles this well by default in Overpass Turbo.[2]
- Alternatively, you can use recursion operators like
> (recurse down) to get members:
relation["type"="route"]["route"="bus"]({{bbox}});
// The line below gets all members (nodes, ways, relations) of the found relations
>>;
// Output the members with geometry
out geom;
```[2]
- Another way to get members of a specific type:
// Find the relation first and store it in a set (e.g., .my_relation)
relation(12345)->.my_relation;
// Query ways that are members of the relation in set .my_relation
way(r.my_relation);
// Output the ways
out geom;
```[2]
Putting it Together (Example: Bus Route 3):
/*
This query finds bus route relations named "Svc 3"
within the current map view (bounding box).
*/
[out:json][timeout:25]; // Settings: output JSON, timeout 25s[6][7][8]
// Query for relations with specific tags within the bounding box
relation["type"="route"]["route"="bus"]["name"="Svc 3"]({{bbox}});[2]
// Output the results with full geometry
out geom;
Remember to adjust the tags (key=value) based on what kind of relation you are looking for. You can explore tags using the OpenStreetMap Wiki or tools like Taginfo.