Overpass Tutorial
- 00 - The Beginning
- 01 - Finding nodes with a bounding box
- 02 - Outputting data about nodes
- 03 - Filtering nodes that have a tag
- 04 - Find nodes by matching tags and their values
- 05 - Find nodes by applying multiple filters
- 06 - Extracting multiple sets of nodes
- 07 - Calculating differences between results
- 08 - Generating JSON output
- 09 - Generating CSV output
- 10 - The default set
- 11 - Querying a set
- 12 - Searching within a radius using around
- 13 - Using around to filter against a set of results
- 14 - Searching by polygon
- 15 - Finding ways
- 16 - Ways and their nodes
- 17 - Ways and their tags
- 18 - Combining node and way queries
- 19 - Finding ways from their nodes
- 20 - Finding relations
- 21 - Type agnostic queries (nwr)
- 22 - Areas
- 23 - Finding the areas enclosing a feature
- 24 - Find the area derived from a feature
- 25 - Areas via Nominatim search
- 26 - Timeouts and endpoints
16 - Ways and their nodes
To create maps for ways, we need to also extract the nodes that describe their outline.
In OverpassQL we do this using the "recurse down" statement ">
".
This statement takes an input set of elements and then finds any node (or way, or relation) that are a member of those elements.
The members of a way are its nodes.
The members of a relation would consist of the nodes and ways that it contains.
Nodes don't have members so these are ignored when performing a traversal.
This query extracts all ways within our bounding box. It then uses a traversal query to also find the members of those nodes.
We then use a union of those two queries to produce output that includes the data about both the way and its nodes.
The recurse operator implicitly uses the default set (_
) as its input. Without
that bit of context, the syntax can seem a bit arcane! It took me a while to understand
what it is doing.
The >
query is very commonly used in queries, as we need it whenever we want
geometry for ways and relations. There is also a version that will traverse all
the way from relations down to nodes: >>
.
If we didn't use the ()
block and just queried for ways and nodes in
turn, then the output would only contain data about the nodes. This is because
the >
query will overwrite the contents of the default set, so we'd lose the
results of our way
query.
Always use a union block when performing traversals unless you really want to
ignore the parent features. Many examples of using OverpassQL just include the
()
block by default, because it's so important for most queries.
Source File | 16-ways-and-their-nodes.osm |
Authors |
|