Overpass turbo/Wizard

From OpenStreetMap Wiki
Jump to: navigation, search
1. Select the Wizard from the toolbar
2. Enter what you want to get
3. Hit the button
4. Enjoy the result

Writing Overpass queries can sometimes be a quite tedious, repetitive work that requires knowledge of one of the Overpass query languages in the first place. Overpass turbo's new Query Wizard helps you by converting simple, human readable search terms into functional Overpass queries. Here is an example: To get drinking water fountains, now all you have to do is fire up the Wizard and type in the appropriate tag amenity=drinking_water, instead of writing down a multi-line Overpass query.

The syntax the Wizard understands is inspired by JOSM's search/filter functions. A search consists of individual filter expressions, for example key=value (for a simple tag search) or type:node (to restrict the result to only nodes). Those can be combined together with logical operations like and or or. Take a look at the following examples:

  • tourism=hotel
  • amenity=drinking_water and type:node
  • (highway=primary or highway=secondary) and type:way

By default, data is searched in the current map viewport. But the Wizard also understands some other location filters. Here is an example of how to search in a certain city:

  • tourism=museum in Vienna

Tag Searches

selector description
key=value

key==value

Matches objects that have a tag with key key and the value value.
key:valuefragment Matches objects that have a tag with key key and whose value contains the string valuefragment.
key~regex

key~=regex
key like regex

Matches objects that have a tag with key key and whose value matches the regular expression regex.
key=*

key==*
key is not null

Matches objects that have a tag with key key.
key!=value

key!==value

Matches objects that do not have a tag with key key and the value value.
key!~regex

key not like value

Matches objects that have a tag with key key and whose value does not match the regular expression regex.
key!=*

key!==*
key is null

Matches objects that do not have a tag with the key key.

If a string (for example the value of one of the tag-selectors above) contains whitespace or other special characters (such as colons, dashes, non-ascii characters, etc.) it must be enclosed in quotes:

  • name="New York"
  • "addr:housenumber" = *

Regular expressions can be provided either as plain strings or with the well known regex notation:

  • ref ~ "[0-9]+"
  • name ~ /street$/i (the modifier i makes the match case-insensitive)

Intelligent Wizard

Instead of tag searches, one can also just filter by object categories. For example one can use the terms Hotel, "Drinking Water", Hospital, etc. instead of the corresponding tags. This works for all objects for which a preset is defined in the iD editor.

Meta-Data Filters

selector description
type:osm-type Matches objects that have the type osm-type (node, way or relation).
id:osm-id Matches objects that have the id osm-id.
user:osm-user Matches objects that were last modified by user osm-user.
uid:osm-uid Matches objects that were last modified by a user with the user-id osm-uid.
newer:date Matches objects that have been added or modified more recently than date.

The parameter date for the newer selector can be either an ISO 8601 time string (e.g. "2013-11-24T19:01:00Z") or a relative date which indicates the relative amount of time in the past:

  • newer:1day (selects everything that has been added or modified in the last 24 hours)
  • newer:"4 weeks"

Allowed time units are: second(s), minute(s), hour(s), day(s), week(s), month(s) and year(s).

Location Filters

By default, the Wizard creates queries that search in the current map view-port (via a <bbox-query {{bbox}}/>). By specifying a location filter at the end of the search you can also search in different places:

selector description
in bbox (default) Matches objects that are inside the current map view-port.
in place Matches objects that are inside an area with the name place.
around place Matches objects that are in the vicinity of an object with the name place.
global Matches objects globally, without any restriction by location.

The place-names mentioned above are passed though a Nominatim search first. That means, you can use any place name that you can also use on OSM's search box, like town names, POIs, addresses, etc.

  • tourism=museum in Vienna
  • amenity=restaurant around "1600 Pennsylvania Ave NW, Washington"
  • tourism=attraction around "Riesenrad, Wien"

Boolean Operators

operator description
X or Y

X || Y, X | Y

Matches when either the objects that have a tag with key key and the value value.
X and Y

X && Y, X & Y

Matches when either the objects that have a tag with key key and the value value.

All boolean operators can be can be used with braces to change operator priorities:

  • (highway=bus_stop or railway=platform) and shelter=yes

Frequently asked questions

  • Q: Does the wizard understands wildcards?
  • A: Yes, you can use wildcards.

Example: You would like to see all ham-radio repeater in a certain region in Germany. The callsigns of the ham-radio repeater in Germany start all with: DB0* examples: DB0XS, DB0SR ... and the callsigns are located in the name tag.

Solution: Use this regular expression: name~"^DB0.*".

Technical Details

The wizard defines it's own grammar written in PEG.js (a simple parser generator for JavaScript). The parsed query (a tree of boolean operations and filters) is then normalized into disjunctive normal form (A∧B∧…) ∨ (X∧Y∧…) ∨ … which is much easier to represent as an Overpass query (i.e. a simple <union> of <query>s). After that, an annotated Overpass-XML query is constructed quite trivially. For some filters special query-shortcuts (such as {{nominatimArea:*}} for an … in Area search) are used.