- 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
06 - Extracting multiple sets of nodes
Sometimes when we are querying for data, we want to build up a larger collection of features that we are interested in. For example, a collection of different types of road, amenities or natural features.
Rather than do this in multiple separate queries, we can extract that collection using a single query, using a union.
In OverpassQL we create a union by specifying a block using curved brackets (
Within that block we can include all of the queries necessary to build our collection
The general syntax is:
For example this query will return all those nodes that have been tagged with the
tourism tag AND those tagged as a cave entrance.
We use separate individual
node statements to build up the collection we want.
out statement will then output the combined results.
This type of query is useful in any context. But its particularly useful for querying the OpenStreetMap database because:
- we are often extracting different types of features, e.g. nodes, ways and relations, and its easier to get these in one pass
- nodes (and ways, and relations) can be tagged in different ways, so we often need to specify variations of tags to collect the features of interest
- by building up larger sets, we can do more complex queries that involve set operations
We'll cover set operations and variables in a later example.