Overpass turbo/Wizard

From OpenStreetMap Wiki
Jump to navigation Jump to search
Overpass API logo.svg
edit
Overpass API · Language reference · Language guide · Technical terms · Areas · Query examples · Sparse Editing · Permanent ID · FAQ · more · Web site
Servers status · Versions · Development · Technical design · Installation · XAPI compatibility layer · Public transport sketch lines · Applications · Source code and issues
Overpass turbo · Wizard · Overpass turbo shortcuts · MapCSS stylesheets · Export to GeoJSON · more · Development · Source code and issues · Web site
Overpass Ultra · Overpass Ultra extensions · MapLibre stylesheets ·more · Source code and issues · Web site
Visit overpass-turbo.eu and follow these steps: # Select the Wizard from the toolbar # Enter what you want to get # Hit the button
4. Enjoy the result

"Overpass" is a system for extracting information from the OSM database ("mining" the database). The Overpass "Query Wizard" helps you do this more easily.

Purpose

To get information from a database you send it a "query" (a question) in a language the computer can understand (the "query language").

Writing Overpass queries requires knowledge of the Overpass query language, and even then can sometimes be quite tedious, repetitive work. Overpass turbo's Query Wizard helps you by converting simple, human readable search terms into functional Overpass queries. An example: To get drinking water fountains, all you have to do is fire up the Wizard and type in the appropriate tag amenity=drinking_water.

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 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, the data to be searched is limited to 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

Intelligent wizard

The simplest way of searching is to use object categories. For example one can use the terms Hotel, "Drinking Water", Hospital, etc. This works for all objects for which a preset is defined in the iD editor.

Tag searches

For the meanings of "key" and "value", please see the glossary.

Selector
with alternatives
Description Example
key=value
key==value
Matches objects that have a tag with the specified key/value pair. tourism=museum
key:valuefragment Matches objects that have a tag with the specified key and whose value contains the string given after the :. cycleway:opp (returns cycleway=opposite, cycleway=opposite_track, cycleway=opposite_lane, etc.)
key~regex
key~=regex
key like regex
Matches objects that have a tag with key key and whose value matches the  regular expression regex.
~keyregex~regex
~keyregex~=regex
Matches objects that have a tag with a key that matches the regular expression keyregex and whose value matches the regular expression regex. ~building~".*" (returns all buildings even with life cycle prefix)
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:
  1. objects that have a tag with key key and whose value does not match the regular expression regex
  2. objects that do not have a tag with key key
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 slashes as  delimiters:

  • ref ~ "[0-9]+"
  • name ~ /street$/i (the modifier i makes the match case-insensitive)
  • image ~ /wikimedia\.commons/ (the escape character \ makes the expression match a literal ".")

Meta-data filters

Selector Description Example
type:osm-type Matches objects of the stated type (node, way or relation). type:node
id:osm-id Matches objects that have the stated osm-id. id:263621287
user:osm-user Matches objects last modified by the user with the stated username. user:SomeonesUsername
uid:osm-uid Matches objects that were last modified by a user with the stated numerical user-id.
newer:date Matches objects that have been added or modified more recently than the stated date/time. (See below for format.)

In the newer selector, the date can be either

  • an ordinary date, given as an  ISO 8601 time string (e.g. "2013-11-24T19:01:00Z") or
  • a relative date indicating 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" (selects everything that has been added or modified in the last 4 weeks)

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

Example: amenity=drinking_water and newer:"4 weeks"

Location filters

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

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. For results falling outside the current view-port, use the Zoom to Data control to locate it.

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. (Take care as you will search all places with that name: there are ways round this by using further search terms.)

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

Boolean operators

Operator
with alternatives
Description Example
X or Y
X || Y,
X | Y
Matches objects which fulfil either the condition X or the condition Y. highway=bus_stop or railway=platform
X and Y
X && Y,
X & Y
Matches objects which fulfil either the condition X and the condition Y. highway=bus_stop and shelter=yes

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

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

Wizard filled by URL-parameter

You can create links to overpass turbo that use the query wizard to create a query (which is loaded on startup and presented to the user). An example is http://overpass-turbo.eu/?w=pub+in+dublin. Such URLs to overpass turbo are both quite short and at least somewhat human readable.

By appending &R to this link, the query will be executed immediately and query results are shown on the map. Example: http://overpass-turbo.eu/?w=pub+in+dublin&R

This feature is also utilized by the search engine DuckDuckGo: You can simply type your query in their search box accompanied by !otw (which stands for "Overpass Turbo Wizard") and when starting the search you are immediately taken to the overpass turbo page with the query you entered.

You can use wildcards

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* (two examples: DB0XS, DB0SR) and the callsigns are located in the name tag.

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

The supported wildcard syntax is called "POSIX extended regular expressions".

So far, when searching for a tag that consists of key=value, wildcards are only possible when defining the value of a tag, you cannot apply any wildcard to the key. Feature to search also for a key via regular expression is available now, see above.

Timeout

By default, [timeout:25] is part of the query. It means that query will be stopped after running for 25 seconds. In some situations one may wish to increase this value to allow queries to run for a longer time.

Limitations

With in-browser use of Overpass turbo Wizard it is impossible to cause too much traffic on servers (except deliberately malicious use). See Overpass_API#Introduction ("You can safely assume...")

Technical details

The wizard syntax is inspired by JOSM's search/filter functions. The wizard defines its 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 queries). After that, an annotated Overpass QL query is constructed quite trivially. For some filters special query-shortcuts (such as {{geocodeArea:*}} for an … in Area search) are used.