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
22 - Areas
This query finds all natural rock formations within Uluṟu-Kata Tjuta National Park.
The results include Uluṟu, Kata Tjuta, Taputji and Mala Kata.
Kata Tjuta is a more complex rock formation and is represented as a relation in
the OSM database. So if we had used only a way
query then it wouldn't be present
in the results. The wr
query lets us do a type agostic query to find the areas
of interest.
So far we've written queries to find nodes, ways and relations. But in this query
we are using a new statement: area
.
Areas are interesting in that they are not formally part of the OSM data model. They are features which have been automatically added to the databases that power the Overpass API. This means that they can be queried and manipulated via the API, but they're not something you can edit.
Areas are automatically created for a range of different types of ways and relations, including:
- any relation with a
type
ofmultipolygon
and aname
- any relation with a
type
ofboundary
and aname
- any relation that has an
admin_level
andname
attribute - any relation with a
postal_code
oraddr:postcode
- a wide range of different named ways including buildings, highways, natural features, leisure areas, places, historic and tourism areas
The complete list is evolving over time.
Areas then are a set of features that are derived from a subset of the ways and relations that exist in the wider database.
From a query perspective, you can think of them like other elements and find them using the standard range of filters.
For example in this query we're finding an area based on its name.
area["name"="Uluru-Kata Tjuta National Park"]
The advantage of using areas rather the original ways and relations is that the API and query language provides some additional functionality for working with them.
For example in this query we're using an area
filter, like this:
way(area);
The area
filter restricts the ways (or nodes, or relations) we're interested in
to just those that within an area we've already found. This type of spatial query
isn't normally available for ways and relations. I presume this is to limit the amount
of indexing required to support this type of query.
The area
query and the area
filter both work with named sets. By default they work
with the default set (_
). And this is what the example query uses.
But an alternate way to write this example is to explicitly store the area we're interested in a named set. I find this a bit clearer in practice.
Here's how this would look, using a named set called ourArea
:
``` area["name"="Uluru-Kata Tjuta National Park"]->.ourArea; ( way(area.ourArea)["natural"="bare_rock"];
; ); ```
If we wanted to instead find nodes or relations then we could use either of the following:
node(area.ourArea);
relation(area.ourArea);
Links | |
Source File | 22-areas.osm |
Authors |
|