Overpass API/Overpass QL and User:Xxzme/Overpass QL: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
m ("... bceause ..." -> "... because ...")
 
No edit summary
 
Line 1: Line 1:
blanked this old unmaintained page (user is permanently blocked since 17 september 2015) to avoid leaving broken links or categories (the content is still in the history)
{{Languages|Overpass API/Overpass QL}}{{Overpassapi}}

'''Overpass QL''' (short for "Overpass Query Language") is the second query language created for the [[Overpass API]], the first being [[Overpass_API/Language_Guide#The Overpass API languages|Overpass XML]]. Overpass QL is a {{Wikipedia|en|Procedural programming|procedural|text=no}}, {{Wikipedia|en|Imperative programming|imperative|text=no}} programming language written with a {{Wikipedia|en|C syntax|C style syntax|text=no}}.

This wiki page intends to be a complete technical reference to the structure of Overpass QL. For a collection of '''practical examples''', see also the wiki page [[Overpass API/Overpass API by Example|Overpass API by Example]]. People without a technical background may find that page more accessible.

{{Ambox
| type = notice
| text = The features supported by an Overpass QL parser are defined by the [[Overpass API/versions|version of the Overpass API]] running on the server queried. Be sure that the [[Overpass_API#Public_Overpass_API_instances|Overpass API server you query]] has a new enough API version to support the features you wish to use.

Where known, a feature's minimum Overpass API version number is specified.
}}

== Language overview ==

=== Statements ===
Overpass QL source code is divided into ''statements,'' and every statement ends with a semicolon <code>;</code>. Statements are executed sequentially by a ''{{Wikipedia|en|Process (computing)|process|text=no}}'', and each statement run changes the process's ''execution state.''

=== Execution state ===
The Overpass QL ''execution state'' consists of:
* the default ''set'' <code>_</code> (a single underscore)
* other named sets, if created by the user
* a {{Wikipedia|en|Stack (abstract_data_type)|stack|text=no}}, during the execution of Overpass QL ''block statements''

=== Sets ===
Overpass QL manipulates ''sets''. Statements write their results into sets, and sets are then read by subsequent statements as input. An Overpass QL set can contain any combination of (and any number of) OpenStreetMap [[Node|nodes]], [[Way|ways]], [[Relation|relations]], and [[area]] [[elements]].

Unless you specify a ''named set'' as an input or result, all input is implicitly read from (and all results are written to) the default set named <code>_</code> (a single underscore). Once a new result is (implicitly or explicitly) assigned to an existing set, its previous contents will be replaced and are no longer available. Overpass QL sets always have global {{Wikipedia|en|Scope (computer_science)|scope (visibility)|text=no}}.

For example:

<syntaxhighlight lang="cpp">
node[name="Foo"];
</syntaxhighlight>

implicitly writes the result of the [[Tags|tag]] query <code>name="Foo"</code> to the default set <code>_</code>, overwriting any previous contents with this result. A result can be written to a specific set using the <code>-></code> syntax, when that set name is prefixed with <code>.</code>. The statement above is thus equivalent to:

<syntaxhighlight lang="cpp">
node[name="Foo"]->._;
</syntaxhighlight>

Similarly, this statement:

<syntaxhighlight lang="cpp">
(
node[name="Foo"];
node[name="Bar"];
);
</syntaxhighlight>

combines the results of two tag queries with a ''union statement'', then sends that result to the default set <code>_</code>. It is equivalent to:

<syntaxhighlight lang="cpp">
(
node[name="Foo"];
node[name="Bar"];
)->._;
</syntaxhighlight>

To write elements to a named set, again use the <code>-></code> syntax, followed by the set name. For example, this query:

<syntaxhighlight lang="cpp">
(node[name="Foo"];)->.a;
</syntaxhighlight>

will write all node elements with the tag <code>name=Foo</code> into the named set <code>a</code>. After this query, you have now 2 sets, the set <code>a</code>, with only the node elements, and the set <code>_</code>, unchanged.

Set names may consist of letters, digits, and the underscore; however, they must not start with a digit.

To read elements from a set, append <code>.</code> and the set name to the command.

<syntaxhighlight lang="cpp">
node.a[amenity=foo];
</syntaxhighlight>

will return all nodes in the named set <code>a</code> that have the [[key]] <code>amenity</code> with the [[value]] <code>foo</code>.

=== Language structure ===
There are several different types of Overpass QL ''statements''. They are grouped into:
* ''Settings,'' which are optional, global variables, set in the first statement of the query. Examples of ''settings'' are the server timeout for the Overpass API server, and the output format of the Overpass QL query.
* ''Block statements'': Block statements group Overpass QL statements together, to enable {{Wikipedia|en|Logical disjunction|disjunctions (truth tests)|text=no}}, as well as loops.
* ''Standalone queries'': These are complete statements on their own. They may perform functions such as querying the Overpass API server to create a set; manipulating the contents of an existing set; or sending the end results of a query to an output location. Standalone queries are themselves comprised of smaller Overpass QL language components, such as evaluators, filters, and operators.

=== Brackets ===
QL syntax uses ''round brackets'' (), ''square brackets'' [] and ''curly brackets'' {}. This documentation page uses the term ''brackets'' for ''square brackets''. See also [https://en.wikipedia.org/wiki/Bracket Wikipedia] for nomenclature.

== Settings ==
Overpass QL ''settings'' must be declared in the first uncommented statement of the Overpass QL source code. Settings cannot be declared in multiple statements.

Settings declarations are enclosed in brackets <code>[]</code>. A colon <code>:</code> appears between the setting name and the value or values to be set. The settings statement must be terminated with a semicolon <code>;</code>.<syntaxhighlight lang="cpp">
// This is a typical settings declaration line
// on an Overpass Turbo server
[out:json][timeout:25];
</syntaxhighlight>

=== ''timeout:'' ===
The ''timeout:'' setting has one parameter, a non-negative integer. Default value is ''180''.

This parameter indicates the maximum allowed runtime for the query in seconds, as expected by the user. If the query runs longer than this time, the server may abort the query with a timeout. The second effect is, the higher this value, the more probably the server rejects the query before executing it.

So, if you send a really complex big query, prefix it with a higher value; e.g., "3600" for an hour. And ensure that your client is patient enough to not abort due to a timeout in itself.

Example:

<syntaxhighlight lang="cpp">
[timeout:180]
</syntaxhighlight>

=== Element limit (''maxsize:'') ===
The ''maxsize:'' setting has one parameter, a non-negative integer. Default value is ''536870912'' (512 MB).

This parameter indicates the maximum allowed memory for the query in bytes RAM on the server, as expected by the user. If the query needs more RAM than this value, the server may abort the query with a memory exhaustion. The second effect is, the higher this value, the more probably the server rejects the query before executing it.

So, if you send a really complex big query, prefix it with a higher value; e.g., "1073741824" for a gigabyte. The maximum value highly depends on the current server load, e.g. requests for 2GB will likely be rejected during peak hours, as they don't fit into the overall resource management. Technically speaking, maxsize is treated as a 64bit signed number.

Example:

<syntaxhighlight lang="cpp">
[maxsize:1073741824]
</syntaxhighlight>

'''Important notice''': Recently, a new mechanism was introduced to abort queries exceeding 2 GB of memory. This exact size of this limit is still under discussion and might change over time.
If you experience error messages like "runtime error: Query run out of memory using about 2048 MB of RAM.", be sure to read [http://permalink.gmane.org/gmane.comp.gis.openstreetmap.overpass/237 this thread] as well.

=== Output format (''out:'') ===
<small>The ''out:'' global setting is unrelated to the ''out'' statement. Syntax should not be mixed.</small>

The ''out'' setting defines the output format used to return OSM data. It can take one of the five values; default value is ''xml'':

*''xml''
*''json'' <small> ''(not to be confused with geoJSON)'' </small>
*''csv''
*''custom''
*''popup''

Example:

<syntaxhighlight lang="cpp">
[out:json]
</syntaxhighlight>

==== CSV output mode ====

CSV output format returns OSM data as [[wikipedia:en:Delimiter-separated values|csv document]], which can be directly opened in tools like LibreOffice. It requires additional configuration parameters to define a list of fields to display, as well as two optional parameters for adding/removing the CSV header line and changing the column separator.

Format:

<syntaxhighlight lang="cpp">
[out:csv( fieldname_1 [,fieldname_n ...] [; csv-headerline [; csv-separator-character ] ] )]
</syntaxhighlight>

Notes:
* Numeric values (coordinates, ids) uses no thousands separator, and uses the English dot (.) for the decimal separator (in geometric coordinates).
* No escaping is made on for specific characters in string values. This will change with release 0.7.55.
* The default separator character (tab) should still allow most of the time to parse the tabular data without missing/broken/misaligned columns.
* These CSV defaults may still not match what your spreadsheet application expects (notably the decimal separator in non-English versions) if you open the CSV file directly with your application, and data could seem corrupted, or unparsable: instead, import the data in a text-only column of a new spreadsheet, and convert it to tabular data inside that application using your own settings; or use an external filter script to convert the file before opening it.

===== Simple example =====
<nowiki>[out:csv(name)]</nowiki> will output just name tag. See below for more complicated examples.

===== List of field names =====

Besides normal OSM field names (tags), special fields are available for each element in the result set to output. Note that all of these special field names need to be prefixed by two colons <code>::</code>.

{| class="wikitable"
|-
! Special field name
! Description
|-
|<code>::id</code>
| OSM Object ID
|-
|<code>::type</code>
| OSM Object type: node, way, relation
|-
|<code>::otype</code>
| OSM Object as numeric value
|-
|<code>::lat</code>
| Latitude (available for nodes, or in ''out center'' mode)
|-
|<code>::lon</code>
| Longitude (available for nodes, or in ''out center'' mode)
|-
| colspan="2" | The following meta information fields are '''only''' available if <code>out meta;</code> is used to output OSM elements.
|-
|<code>::version</code>
| OSM object's version number
|-
|<code>::timestamp</code>
| Last changed timestamp of an OSM object
|-
|<code>::changeset</code>
| Changeset in which the object was changed
|-
|<code>::uid</code>
| OSM User id
|-
|<code>::user</code>
| OSM User name
|-
| colspan="2" |The following meta information fields are '''only''' available if <code>out count;</code> is used to output OSM elements.
|-
|<code>::count</code>
|Returns total number of objects (nodes, ways, relations and areas) in inputset
|-
|<code>::count:nodes</code>
|Returns number of nodes in inputset
|-
|<code>::count:ways</code>
|Returns number of ways in inputset
|-
|<code>::count:relations</code>
|Returns number of relations in inputset
|-
|<code>::count:areas</code>
|Returns number of areas in inputset
|}

Example:

<syntaxhighlight lang="c">
[out:csv(
::"id", amenity, name, operator, opening_hours, "contact:website", "contact:phone", brand, dispensing, lastcheck
)];
</syntaxhighlight>

Railway stations in Bonn:

{{OverpassTurboExample|loc=50.51201;8.09641;12|query=
[out:csv(::id,::type,"name")];
area[name="Bonn"];
nwr(area)[railway=station];
out;
}}

===== CSV header line =====

The presence or absence of a header line can be controlled by the first optional parameter, which can be added right after the field list separated by semicolon. Possible values include ''true'' and ''false''. Default value is ''true''.

<syntaxhighlight lang="c">
[out:csv(
::"id", amenity, name, operator, opening_hours, "contact:website", "contact:phone", brand, dispensing, lastcheck;
false
)];
</syntaxhighlight>

===== CSV separator character =====

By default all fields are separated by a tab character ("\t"). However, this setting can be changed via the second optional parameter. In the following example all output fields will be separated by a pipe ("|") character instead

<syntaxhighlight lang="c">
[out:csv(
::"id", amenity, name, operator, opening_hours, "contact:website", "contact:phone", brand, dispensing, lastcheck;
true; "|"
)];
</syntaxhighlight>

; Checking CSV output for complete data

Unlike other output modes like XML and JSON, there's currently no indication of any error message at all. An empty result (or a result with just a header line) might indicate either that nothing was found or that the query was aborted due to timeout or some other more serious error condition. One way to work around this is to introduce an additional counter, which summarizes the previous query result and is always put as the very last output statement of a query.

The following example extends the previously shown list of all railway stations in Bonn by an additional output statement returning an additional aggregated row in the CSV, describing a pseudo-element with type "count" and whose value will be in the last requested <code>::count</code> column (whose value remains empty for normal data rows):

<syntaxhighlight lang="cpp">
[out:csv(::type,::id,"name",::count)];
area[name="Bonn"]->.a;
( node(area.a)[railway=station];
way(area.a)[railway=station];
rel(area.a)[railway=station];
);
out;
out count;
</syntaxhighlight>

The output now includes an additional column with type <code>::count</code> and an indication of how many total elements are contained in the current resultset: 5. If the final count line is missing or the total number differs, you know for sure that something went wrong and the query results are incomplete/inconsistent.

<pre>
@type @id name @count
node 26945519 Bonn-Oberkassel
node 1271017705 Bonn-Beuel
node 2428355974 Bonn-Bad Godesberg
node 2713060210 Bonn Hauptbahnhof
node 3400717493 Bonn-Mehlem
count 0 5

</pre>

The values ''custom'' and ''popup'' also require further configuration. Please see details in the [http://dev.overpass-api.de/output_formats.html output formats documentation].

=== Global bounding box (''bbox'') ===
The '[[#Bounding box|bounding box]]' defines the map area that the query will include. The global ''bbox'' setting can be used to define a bounding box and then this is implicitly used in all statements (unless a statement specifies a different explicit bbox). If no ''bbox'' is specified the default value is "the entire world".

In a standard Overpass QL program, a bounding box is constructed with two decimal degree coordinate pairs in [http://en.wikipedia.org/wiki/ISO_6709 ISO 6709 standard order and format], and each value is separated with a comma. The values are, in order: ''southern-most latitude'', ''western-most longitude'', ''northern-most latitude'', ''eastern-most longitude.''

<syntaxhighlight lang="cpp" line="1">
[bbox:south,west,north,east]
// A bbox framing the German city of Bonn
[bbox:50.6,7.0,50.8,7.3]
// A bbox framing part of Rio de Janeiro, Brazil
[bbox:-23,-43.3,-22.8,-43.1]
</syntaxhighlight>

'''Note:''' When a query is URL encoded as the value of the <code>data=</code> parameter, a bounding box can also be appended as a separate <code>bbox</code> variable. When used this way, the order is reversed, ''lon-lat''. (This is the common order for [http://openlayers.org/ OpenLayers] and other frameworks.)

The Bonn example, above, as used in a URL encoding:

<syntaxhighlight lang="http">
/api/interpreter?data=[bbox];node[amenity=post_box];out;&bbox=7.0,50.6,7.3,50.8
</syntaxhighlight>

This finds all post boxes roughly in Bonn, Germany.

=== Date ===

''date'' is a global setting which modifies an Overpass QL query to examine [[Attic Data|attic data]], and return results based on the OpenStreetMap database as of the date specified. This setting can be useful, for example, to reconstruct data that has been vandalized, or simply to view an object as it existed in the database at some point in the past.

It consists of the identifier <code>date</code>, followed by <code>:</code> and then an OpenStreetMap database standard [https://en.wikipedia.org/wiki/ISO_8601 ISO 8601] date enclosed in quotes, in the format <code>YYYY-MM-DDThh:mm:ssZ</code>.

This example queries the state of the database on 28th October 2015 at 19:20:00 UTC:<syntaxhighlight lang="cpp" line="1">
[date:"2015-10-28T19:20:00Z"]
</syntaxhighlight>

There is no attic data in the OpenStreetMap database with a date earlier than <code>2012-09-12T06:55:00Z</code> (1347432900 in epoch seconds). This date corresponds to the first change included in the [[ODbL]] compliant planet file. Use of an earlier <code>date</code> setting is technically possible, but doing so will always return the database state as of <code>2012-09-12T06:55:00Z</code>.

=== Difference between two dates (''diff'') ===
The ''diff'' setting lets the database determine the difference of two queries at different points in time. This is useful for example to deltas for database extracts.

It consists of the identifier <code>diff</code>, followed by <code>:</code> , an OpenStreetMap database standard [https://en.wikipedia.org/wiki/ISO_8601 ISO 8601] date enclosed in quotes, in the format <code>YYYY-MM-DDThh:mm:ssZ</code> , and optionally a comma and a second date which defaults to the current date ("now").

Example:

<syntaxhighlight lang="cpp" line="1">
[diff:"2012-09-14T15:00:00Z"]
</syntaxhighlight>

This processes the rest of the query as if it were posed on 14th September 2012 at 15:00, then processes the same query with current data and finally outputs the difference between the two results.

<syntaxhighlight lang="cpp" line="1">
[diff:"2012-09-14T15:00:00Z","2012-09-21T15:00:00Z"]
</syntaxhighlight>

Does basically the same, but compares the state of 14th September with the state of 21st September.

Note that the output does not include any intermediate versions, which might exist between the first and the last timestamp, i.e. if there are several changes on an object, only the last version in the given timeframe is returned.

=== Augmented-difference between two dates (''adiff'') ===

The ''adiff'' does basically the same as ''diff'' , but for all elements that aren't contained in the newer result, it is indicated what happened to them.

If an element has been deleted, then its last deletion date is printed and the indication "visible=false". If an element has changed such that it no longer matches the query then its last change date is printed and the indication "visible=true".

For more information see: [[Overpass_API/Augmented_Diffs|Augmented Diffs]].

== Block statements ==

=== Union ===
The ''union'' block statement is written as a pair of parentheses. Inside the ''union'', any sequence of statements can be placed, including nested ''union'' and ''foreach'' statements. Note that the square brackets '''[ ... ]''' shown below indicate an optional part of the syntax and are not to be typed literally.

<syntaxhighlight lang="cpp">
(statement_1; statement_2; …)[->.result_set];
</syntaxhighlight>

The ''union'' block statement takes no input set. It produces a result set which is the union of the result sets of all sub-statements, regardless of whether a sub-statement has a redirected result set or not.

Example:

<syntaxhighlight lang="cpp">
(node[name="Foo"]; way[name="Foo"];);
</syntaxhighlight>

The first statement collects all nodes that have a name tag "Foo"; the second statement collects all ways that have a name tag "Foo". After the union statement, the result set is the union of the result sets of both statements.

The result set of the union statement can be redirected with the usual postfix notation.

Example:

<syntaxhighlight lang="cpp">
(node[name="Foo"]; way[name="Foo"];)->.a;
</syntaxhighlight>

This is the same as the preceding example, but the result is written into the variable ''a''.

'''Limitation:''' Note that ''foreach'' and ''print'' statements cannot be sub-elements of element ''union''.

=== Difference ===
The ''difference'' block statement is written as a pair of parentheses. Inside the ''difference'' statement, exactly two statements must be placed, separated by a minus sign. Note that the square brackets '''[ ... ]''' shown below indicate an optional part of the syntax and are not to be typed literally.

<syntaxhighlight lang="cpp">
(statement_1; - statement_2;)[->.result_set];
</syntaxhighlight>

The ''difference'' block statement takes no input set. It produces a result set which contains all elements that are result of the first sub-statement and not contained in the result of the second sub-statement.

Example:

<syntaxhighlight lang="cpp">
(node[name="Foo"]; - node(50.0,7.0,51.0,8.0););
</syntaxhighlight>

This collects all nodes that have a name tag "Foo" but are not inside the given bounding box.

The result set of the difference statement can be redirected with the usual postfix notation.

Example:

<syntaxhighlight lang="cpp">
(node[name="Foo"]; - node(50.0,7.0,51.0,8.0);)->.a;
</syntaxhighlight>

This is the same as the preceding example, but the result is written into the variable ''a''.

=== Intersection ===
It is also possible to produce a set of elements that appear in both of two input sets, i.e. elements that are part of both sets. This is described below in [[#By_input_set_(.setname)|By input set (.setname)]]:
<syntaxhighlight lang="cpp">
node.a.b;
</syntaxhighlight>

This is not a block statement, but is listed here because of its close relation to the difference statement described above.

=== The block statement ''if'' ===

''since v0.7.55''

The block statement ''if'' executes its substatements only if its condition evaluates to boolean true. This allows e.g. to try more loosely search conditions if stricter search conditions did not deliver a result.

The statement does not directly interact with any sets.

The base syntax is

if (<Evaluator>)
{
<List of Substatements>
}

resp.

if (<Evaluator>)
{
<List of Substatements>
}
else
{
<List of Substatements>
}

where <Evaluator> is an evaluator and <List of Substatements> is a list of substatements.

=== For-each loop (''foreach'') ===
''since v0.7.51''

The ''foreach'' block statement is written as the keyword ''foreach'', followed by a pair of curly braces. Any sequence of statements can be placed between these braces, including nested ''union'' and ''foreach'' statements.

The ''foreach'' block statement takes an input set and produces no result set. The ''foreach'' statement loops over the content of the input set, once for every element in the input set.

Example:<!--syntax pretty printed with whitespaces for easier understanding, see below-->

<syntaxhighlight lang="cpp">
way[name="Foo"];
foreach
{
(
._;
>;
);
out;
}
</syntaxhighlight>

For each way that has a name tag with value "Foo", this prints the nodes that belong to this way immediately followed by the way itself. In detail, the result set of ''way[name="Foo"]'' is taken as the input set. Then, for each element in this input set, the loop body is executed once. Inside the loop body, the union of the element and its nodes is taken. This union is then printed.

Note that during execution, each printed subset in an iteration is independent of subsets printed in other iterations, possibly resulting in duplicate objects in the global output (no union is computed by the ''out'' statement within the loop).

The input set of the foreach statement can be taken from a variable with the usual postfix notation:

Example:

<syntaxhighlight lang="cpp">
foreach.a(...);
</syntaxhighlight>

This loops over the content of set ''a'' instead of the default set "_".

The name of the variable to put the loop element into can also be chosen by adding a postfix immediately before the opening parenthesis.

Example:

<syntaxhighlight lang="cpp">
foreach->.b(...);
</syntaxhighlight>

This puts the element to loop over into the variable ''b''. Without it, the ''foreach'' statement does not put the elements into any set.

Example for both input and loop set changed:

<syntaxhighlight lang="cpp">
foreach.a->.b(...);
</syntaxhighlight>

Note that the input set can't be altered by the loop. Any updates to the set will be saved for further usage, but this will not alter the number of iterations.

=== The block statement ''for'' ===

''since v0.7.55''

The block statement ''for'' divides its input into subsets and executes all the statements in the loop body once for every subset.

The input set is broken down as follows: For each element the given evaluator is evaluated and elements with the same value are grouped together. At the beginning of each loop execution, the output set is filled with the relevant subset.

The base syntax is

for (<Evaluator>)
{
<List of Substatements>
}

The input and output set can be specified between ''for'' and the opening parenthesis,
i.e. you set the input set

for.<Name of Input Set> (<Evaluator>)
{
<List of Substatements>
}

or the output set

for->.<Name of Output Set> (<Evaluator>)
{
<List of Substatements>
}

or both

for.<Name of Input Set>->.<Name of Output Set> (<Evaluator>)
{
<List of Substatements>
}

Within the loop, the value of the evaluator is available via the property ''val'' of the output set. I.e., with

<Output Set>.val

you can access the value of the expression for this loop.

With the special evaluator ''keys()'', one can loop over all the keys that exist in the subset.
The respective subset for each key are the elements that have this key set.
Unlike for a usual evaluator, the sets are not mutually distinct in that case.

=== The block statement ''complete'' ===

''since v0.7.55''

The block statement ''complete'' loops through its substatements until the results of the loop stabilize.
This allows to track a group of loosely or tightly connected elements like all sections of a way with the same name or a system of tributary rivers.

The statement delivers the accumulated elements in its output set both at the beginning of each loop execution and as output of the whole statement.

The elements are accumulated from the input set before entering the loop and again from the input set at the end of the loop.
If the input set contains extra elements then the loop is executed again.

The base syntax is

complete
{
<List of Substatements>
}

where <List of Substatements> is a list of substatements.

The maximum number of loops defaults to 4096.
This value can be changed to any value between 1 and 1048576 for this loop.
To do so, put the desired value in parentheses after the "complete" keyword:

complete(<Number>)
{
<List of Substatements>
}

The input and output set can be specified between complete and the opening parenthesis; i.e. you set the input set

complete.<Name of Input Set>
{
<List of Substatements>
}

or the output set

complete->.<Name of Output Set>
{
<List of Substatements>
}

or both

complete.<Name of Input Set>->.<Name of Output Set>
{
<List of Substatements>
}

resp.

complete(<Number>).<Name of Input Set>->.<Name of Output Set>
{
<List of Substatements>
}

=== The block statement ''retro'' ===

''since v0.7.55''

The block statement ''retro'' executes its substatements for the date given in the evaluator.

It is currently undefined whether the content of variables from outside the block is available within the block and vice versa.
Future versions may transfer only derived elements, keep the environments completely apart, or morph elements from one point in time to the other.

The base syntax is<syntaxhighlight lang="cpp">
retro (<Evaluator>)
{
<List of Substatements>
}
</syntaxhighlight>where <Evaluator> is an evaluator and <List of Substatements> is a list of substatements.

=== The block statement ''compare'' ===
''since v0.7.55''

The statement ''compare'' computes the diff of the data of two timestamps.
That diff can consist of any elements as well as only those with specific properties.

The statement can have a block of substatements.
The block of substatements is executed after computing the diff in the second run, once for the old timestamp and then again for the new timestamp.
This allows to do extra computations based on the diff results.

The statement can only be used in diff mode.
In other modes its behaviour is undefined, and in future versions it might be a syntax error to have it elsewhere.

In the first run of a diff query it returns an empty set.
In the second run of a diff query it returns the difference of the elements.
If the statement gets an evaluator as argument then only those elements that have different values on both timestamps are returned.
If the element does not exist on one of the timestamps then its value is regarded as the empty string.
Currently, the only purpose of such a difference is to feed it into an output statement.

The base syntax is

compare();

In addition, an input and/or output set can be specified:

.<Set> compare()->.<Set>;

With the evaluator, the syntax becomes

compare(delta:<Evaluator>);

resp.

.<Set> compare->.<Set>(delta:<Evaluator>);

In all syntax variants a block of substatements can be attached:

compare()
{
<List of Substatements>
};

resp.

.<Set> compare(delta:<Evaluator>)->.<Set>;
{
<List of Substatements>
};


== Standalone statements ==

=== out ===

<small>The ''out'' statement is unrelated to the ''out:'' global setting. Syntax should not be mixed.</small>

The ''out'' statement outputs the contents of a set. It is ''almost always used'' in any Overpass QL query.

<code>out count;</code> is a statement which prints ''only'' the [[#Statistical Count|total ''counts'' of elements]] in the input set by type (nodes, ways, relations, areas). It cannot be combined with anything else.

The simplest form of the out statement has several implied defaults.
<syntaxhighlight lang="cpp">
out; // Simplest form of the out statement
._ out body; // Identical meaning to the above
</syntaxhighlight>
The default input set <code>_</code> can be overridden by prepending a period and a named set name to the out statement.
<syntaxhighlight lang="cpp">
.mystuff out; // Output the named set 'mystuff'
</syntaxhighlight>
The ''out'' statement can be configured with an arbitrary number of parameters that are appended, separated by whitespace, between the word ''out'' and the semicolon.

Allowed values, in any order, are:

* One of the following for the '''degree of verbosity''' of the output; the default is <code>out body</code>:
**<code>out ids</code>: Print only the ids of the elements in the set.
** <code>out skel</code>: Print the minimum information necessary for geometry:
***for nodes: id and coordinates
***for ways: id and the ids of its member nodes
***for relations: id of the relation, and the id, type, and role of all of its members.
** <code>out body</code>: Print all information necessary to use the data. These are also tags for all elements and the roles for relation members.
** <code>out tags</code>: Print only ids and tags for each element and not coordinates or members.
** <code>out meta</code>: Print everything known about the elements. meta includes everything output by body for each OSM element, as well as the version, changeset id, timestamp, and the user data of the user that last touched the object. Derived elements' metadata attributes are also missing for derived elements.

{| class="wikitable"
!
!Own object type
!Own object ID
!For nodes:
Own coordinates
!For ways:
IDs of member nodes
!For relations:
ID, type, role of members
!Own tags
!Timestamp, Version, Changeset, User, User ID
|-
!<code>out ids</code>
|{{yes}}
|{{yes}}
|
|
|
|
|
|-
!<code>out skel</code>
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|
|
|-
!<code>out body</code>
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|
|-
!<code>out tags</code>
|{{yes}}
|{{yes}}
|
|
|
|{{yes}}
|
|-
!<code>out meta</code>
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|}

* The '''modificator''' <code>noids</code> lets all ids to be omitted from the statement. (Note: As of 2021-12-28, there is a [https://github.com/tyrasd/overpass-turbo/issues/547 bug in Overpass Turbo] preventing the usage of noids.)

* One of the following '''modificators for geolocated information'''; default is to print none:
**<code>geom</code>: Add the full geometry to each object. This adds coordinates to each node, to each node member of a way or relation, and it adds a sequence of "nd" members with coordinates to all relations.
** <code>bb</code>: Adds only the bounding box of each element to the element. For nodes this is equivalent to <code>geom</code>. For ways it is the enclosing bounding box of all nodes. For relations it is the enclosing bounding box of all node and way members, relations as members have no effect.
** <code>center</code>: This adds only the centre of the above mentioned bounding box to ways and relations. Note: The center point is not guaranteed to lie inside the polygon ([http://overpass-turbo.eu/s/4rr example]).

* A '''bounding box''' in the format <code>(south,west,north,east)</code> (normally used with the ''geom'' verbosity type). In this case, only elements whose coordinates are inside this bounding box are produced. For way segments, the first or last coordinates outside this bounding box are also produced to allow for properly formed segments (this restriction has no effect on derived elements without any geometry).

* One of the following for the '''sort order''' can be added:
**<code>asc</code>: Sort by object id (default).
** <code>qt</code>: Sort by quadtile index; this is roughly geographical and significantly faster than order by ids (derived elements generated by ''make'' or ''convert'' statements without any geometry will be grouped separately, only sorted by id).
* A non-negative integer, which '''limits the output''' to a maximum of the given number. If not specified, the entire set will be output. For instance, <code>out 12;</code> will output at most 12 features.

=== Item ===
The ''item'' standalone query consists only of an input set prefix.

It takes the input set specified by its prefix. This is in particular useful for union statements: it reproduces its input set as (part of the) result of the union statement.

The most common usage is the usage with the default input set, <code>_</code>, as shown below.

<syntaxhighlight lang="cpp">
._;
</syntaxhighlight>

The following union statement will join all items in the default input set with the default input set's [[Overpass API/Overpass QL#Recurse down (%3E)|recurse down]] result. It will then output the result back to the default input set, overwriting it.

<syntaxhighlight lang="cpp">
(._; >;);
</syntaxhighlight>

But of course other sets are possible too:

<syntaxhighlight lang="cpp">
.a;
</syntaxhighlight>

In the context of a union statement:

<syntaxhighlight lang="cpp">
(.a; .a >;);
</syntaxhighlight>

Note: Subsequent statements in a union statement are not impacted by the ''item'' statement. In particular, <code>.a;</code> does not add the contents of the input set to <code>_</code>, the default item set.

The item statement can also be used as a filter.

=== Recurse up (''<'') ===
The ''recurse up'' standalone query is written as a single less than symbol, "<".

It takes an input set. It produces a result set. Its result set is composed of:
* all '''ways''' that have a '''node''' which appears in the '''input''' set; plus
* all '''relations''' that have a '''node or way''' which appears in the '''input''' set; plus
* all '''relations''' that have a '''way''' which appears in the '''result''' set

Example:

<syntaxhighlight lang="cpp">
<;
</syntaxhighlight>

The input set of the recurse up statement can be chosen with the usual prefix notation:

<syntaxhighlight lang="cpp">
.a <;
</syntaxhighlight>

The result set of the recurse up statement can be redirected with the usual postfix notation:

<syntaxhighlight lang="cpp">
< ->.b;
</syntaxhighlight>

Of course, you can also change both:

<syntaxhighlight lang="cpp">
.a < ->.b;
</syntaxhighlight>

=== Recurse up relations (''<<'') ===
The ''recurse up relations'' standalone statement has a similar syntax to the recurse-up statement, but it is written as a double less than.

In particular, you can change the input and/or result set with the same notation as for the ''recurse up'' standalone query.

In addition to the recurse-up results, it continues to follow backlinks onto the found relations until it contains all relations that point to an object in the input or result set.

Precisely, the ''recurse up relations'' standalone query returns the transitive and reflexive closure of membership backwards.

'''Be aware:''' Done on a node or a way, it will return the parents of that node<ref>[https://overpass-turbo.eu/s/UDY An example of expected behaviour when using << on a node]</ref> or way<ref>[https://overpass-turbo.eu/s/UE0 An example of expected behaviour when using << on a way]</ref> (as expected). Done on a relation, it will return '''both''' the relation itself and its parents<ref>[https://overpass-turbo.eu/s/1D6y An example of UNEXPECTED behaviour when using << on a relation]</ref>.
If you want the parents only, you can use: <code>rel._ -> .a; (.a <<; - rel.a;);</code> instead<ref>[https://overpass-turbo.eu/s/1D6C An example of a successful mitigation against the unexpected behavior when using << on a relation]</ref>. The simpler <s><code>(<<; - rel._;);</code></s> would return an empty result for some relations<ref>[https://overpass-turbo.eu/s/1D6A An example of an unsuccessful mitigation against the unexpected behavior when using << on a relation]</ref>.

Syntax:

<syntaxhighlight lang="cpp">
<<;
</syntaxhighlight>

=== Recurse down (''>'') ===
The ''recurse down'' standalone query is written as a single greater than.

It takes an input set. It produces a result set. Its result set is composed of:
* all '''nodes''' that are part of a '''way''' which appears in the '''input''' set; plus
* all '''nodes and ways''' that are members of a '''relation''' which appears in the '''input''' set; plus
* all '''nodes''' that are part of a '''way''' which appears in the '''result''' set

In particular, you can change the input and/or result set with the same notation as for the ''recurse up'' standalone query.

Example:

<syntaxhighlight lang="cpp">
>;
</syntaxhighlight>

=== Recurse down relations (''>>'') ===
The ''recurse down relations'' statement has a similar syntax to the recurse down statement,
but it is written as a double greater than.

In particular, you can change the input and/or result set with the same notation as for the recurse-down standalone query.

It continues to follow the membership links including nodes in ways until for every object in its input or result set all the members of that object are in the result set as well.

Precisely, the ''recurse down relations'' statement returns the transitive and reflexive closure of membership.

Syntax:

<syntaxhighlight lang="cpp">
>>;
</syntaxhighlight>

=== Query for areas (''is_in'') ===

The standalone query ''is_in'' returns the areas and closed ways that cover
* the given coordinates (when specified) or
* one or more nodes from the input set (when no coordinates are specified).

It takes either an input set or a coordinate and produces a result set. The results are all areas which contain at least one of the nodes from the input set or the specified coordinate.

''is_in'' cannot be directly used with any of the Overpass QL filters. For filtering the ''is_in'' result, a further query is needed (see below): the [square brackets] shown below, indicate optional parts and are not part of the syntax to type.

<syntaxhighlight lang="cpp">
[.input_set] is_in [-> .result_set];
is_in(latitude, longitude) [-> .result_set];
</syntaxhighlight>

In its shortest form, it takes its input set as the locations to search for. Example:

<syntaxhighlight lang="cpp">
is_in;
</syntaxhighlight>

The input set can be chosen with the usual prefix notation:

<syntaxhighlight lang="cpp">
.a is_in;
</syntaxhighlight>

The result set can be redirected with the usual postfix notation:

<syntaxhighlight lang="cpp">
is_in->.b;
</syntaxhighlight>

Of course, you can also change both:

<syntaxhighlight lang="cpp">
.a is_in->.b;
</syntaxhighlight>

Instead of taking existing nodes you can also specify coordinates with two floating point numbers, divided by a comma. They are interpreted as latitude, longitude. In this case, the input set is ignored. Example:

<syntaxhighlight lang="cpp">
is_in(50.7,7.2);
</syntaxhighlight>

Also in this variant, the result set can be redirected with the usual postfix notation:

<syntaxhighlight lang="cpp">
is_in(50.7,7.2)->.b;
</syntaxhighlight>

Area creation depends on some specific extraction rules, there's no area counterpart for each and every OSM relation! For more details see [https://github.com/drolbr/Overpass-API/blob/master/src/rules/areas.osm3s areas.osm3s] and the [[Overpass API/Areas|Areas Wiki page]].

To filter the result returned by ''is_in'' by additional filter criteria, an additional query is needed:

<syntaxhighlight lang="cpp">
is_in(48.856089,2.29789);
area._[admin_level="2"]; // ._ represents the default inputset, which contains all areas returned by ''is_in''
</syntaxhighlight>

=== The statement ''timeline'' ===

''since v0.7.55''

The statement ''timeline'' takes type and id of an object and optionally version as arguments.
It then returns a derived structure containing the meta information of the specified version.
If no version is specified then one object for each known version is returned.
Each of these objects has tags ''ref'', ''reftype'', and ''refversion'' to identify the reference.
In addition, it has tags ''created'' and ''expired'' that contain the relevant timestamps.

The base syntax is

timeline(<Type>, <Ref>);

resp.

timeline(<Type>, <Ref>, <Version>);

where <Type> is one of the three literals node, way, or relation.

In addition, an output set <Set> can be specified:

timeline(<Type>, <Ref>)->.<Set>;

resp.

timeline(<Type>, <Ref>, <Version>)->.<Set>;


=== The statement ''local'' ===
''since v0.7.55''

The statement ''local'' converts the given input into the localized representation of OSM data.
The output parameter controls which classes of data are included.

Without a type parameter local delivers geometry and tags.
This is one object per tagged node plus one object per part of a way plus one object per part of a relation geometry.

With the type parameter "ll", it delivers additionally loose objects.
There are one object per way with tags but without node members
and one object per relation member of any relation without node or way members.

With the type parameter "llb", it delivers even more data:
It delivers the objects that associate the OSM element ids to the aforementioned objects.

The base syntax is

local <Type>

where <Type> is empty, "ll", or "llb". You can also specify other input and/or output sets than "_":

.<Set> local <Type> ->.<Set>

The first set is the input set, the second set is the output set.

=== The statement ''convert'' ===
''since v0.7.54''

The statement ''convert'' produces one output element for every element in its input set. Its input and output sets are always the default set.

The content of each output element is controlled by the parameters of the statement. The statement discards geometry (lat/lon info).

The base syntax is

convert <Type> <List of Tags>

where <code><List of Tags></code> is a comma separated list of items,
each of which must be one the following

<Key> = <Evaluator>
::id = <Evaluator>
:: = <Evaluator>
!<Key>

The first parameter, <code><Type></code>, must have a fixed value. <code><Type></code> must start with a letter, and every following character can be either an alphanumeric character or an "_". <code><Type></code> controls the type of each output element.

The following parameters are used to set an arbitrary number of tags on each output element.

In the below description, each <code><Evaluator></code> is evaluated with an input element in context (see [[Overpass API/Overpass QL#Element Dependent Operators]]).

For each element in the input set:

* <code><Key> = <Evaluator></code> adds a key to the corresponding output element with value <code><Evaluator></code> evaluated with key <code><Key></code> (relevant for the [[#Tag Value and Generic Value Operators|generic evaluator]]).
* <code>::id = <Evaluator></code> sets the id of the corresponding output element to the value of <code><Evaluator></code>
* <code>:: = <Evaluator></code> is equivalent to <code><Key> = <Evaluator></code> for every key in the input element. This is called the generic key mechanism.
* <code>!<Key></code> prevents key <code><Key></code> from being set in the output element by the generic key mechanism.

Keys set explicitly with the <code><Key> = <Evaluator></code> syntax override keys set with the generic key mechanism.

If you do not set an id then a unique id from a global ascending counter is assigned.

It is a syntax error to set the same key twice using the <code><Key>=<Evaluator></code> or <code>!<Key></code> items.

=== The statement ''make'' ===
''since v0.7.54''

The statement ''make'' produces a set containing a single output element. Its output set is always the default set. The statement has no input set.

The content of the output element is controlled by the parameters of the statement. The statement cannot produce geometry (lat/lon info) on its output element.

The base syntax is

make <Type> <List of Tags>

where <code><List of Tags></code> is a comma separated list of items,
each of which must be one the following

<Key> = <Evaluator>
::id = <Evaluator>
<Set>:: = <Evaluator>
!<Key>

Note the difference from the ''convert'' statement syntax. In the ''make'' statement, the generic key mechanism requires an explicit input set.

The first parameter, <code><Type></code>, must have a fixed value. <code><Type></code> must start with a letter, then can contain alphanumeric characters and "_". <code><Type></code> controls the type of each output element.

The following parameters are used to set an arbitrary number of tags on the output element.

A description of each parameter item is below. Note that unlike in a ''convert'' statement, there is no element in context for the evaluators, so element dependent operators cannot be used.

* <code><Key> = <Evaluator></code> adds a key to the output element with value <code><Evaluator></code> evaluated with key <code><Key></code> (relevant for the [[#Tag Value and Generic Value Operators|generic evaluator]]).
* <code>::id = <Evaluator></code> sets the id of the output element to the value of <code><Evaluator></code>
* <code><Set>:: = <Evaluator></code> is equivalent to <code><Key> = <Evaluator></code> for every key that appears at least once in an element in <code><Set></code>. This item is called the generic key mechanism.
* <code>!<Key></code> prevents key <code><Key></code> from being set in the output element by the generic key mechanism.

Keys set explicitly with the <code><Key> = <Evaluator></code> syntax override keys set with the generic key mechanism.

If you do not set an id then a unique id from a global ascending counter is assigned.

It is a syntax error to set the same key twice using the <code><Key>=<Evaluator></code> or <code>!<Key></code> items.
Also, at most one generic key can be set.

=== The Query Statement ===

The most important statement is the ''query'' statement. This is not a single statement but rather consists of one of the type specifiers ''node'', ''way'', ''relation'' (or shorthand ''rel''), ''derived'', ''area'', or ''nwr'' (shorthand for "nodes, ways or relations") followed by one or more filters. The result set is the set of all elements that match the conditions of all the filters.

Example:

<syntaxhighlight lang="cpp">
// one filter
node[name="Foo"];
way[name="Foo"];
rel[name="Foo"];
nwr[name="Foo"];
nw[name="Foo"];
nr[name="Foo"];
wr[name="Foo"];
derived[name="Foo"];
area[name="Foo"];

// many filters
node[name="Foo"][type="Bar"];
</syntaxhighlight>

Here, ''node'', ''way'', ''rel'', ''nwr'', ''derived'', and ''area'' are the type specifier, ''[name="Foo"]'' resp. ''[type="Bar"]'' is the filter and the semicolon ends the statement.

The ''query'' statement has a result set that can be changed with the usual postfix notation.

<syntaxhighlight lang="cpp">
node[name="Foo"]->.a;
</syntaxhighlight>

The individual filters may have in addition input sets that can be changed in the individual filters. Please see for this at the respective filter.

=== The Query Filter ===

The query filter can be added as condition to a query statement.
It has an evaluator as argument and it lets pass only those elements for which the expression returns boolean true.

At the moment, the query filter cannot be the only condition in a query.
This is due to implementation reasons and will change in future versions.

It is technically possible to have multiple query filters in a single query.
But it does not make sense:
Their evaluators can be combined with a conjunction in a single query filter.
This has the same semantics and is faster.

Its syntax is

(if: <Evaluator>)

The whitespace is optional.

== Filters ==

=== By tag (''has-kv'') ===
The ''has-kv'' filter selects all elements that have or have not a tag with a certain value. It supports the basic OSM types node, way, and relation as well as the extended type area.

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

All variants consist of an opening bracket, then a string literal in single or double quotes. Then the variants differ. All variants end with a closing bracket. If the string literal consists only of letters, the quotes can be omitted.

==== Equals (''='', ''!='') ====
The most common variant selects all elements where the tag with the given key has a specific value. This variant contains after the key literal an equal sign and a further literal containing the value. Examples, all equivalent:

<syntaxhighlight lang=js>
node[name=Foo];
node[name='Foo'];
node[name="Foo"];
node['name'="Foo"];
node["name"="Foo"];
node["name"='Foo'];
</syntaxhighlight>

If you have a digit, whitespace or whatever in the value, you do need single or double quotes:

<syntaxhighlight lang=js>
node[name="Foo Street"];
node["name:fr"="Rue Feau"];
</syntaxhighlight>

Querying for empty values [https://github.com/drolbr/Overpass-API/issues/92 is not possible] using the <i>equals value</i> operator. This can only be achieved by using a regular expression:

<syntaxhighlight lang="cpp">
node[power=""]; // not supported
node[power~"^$"]; // use regular expression instead
</syntaxhighlight>

Likewise, querying empty key values is also not possible using this kind of key-value query and needs to be expressed via regular expressions.

<syntaxhighlight lang="cpp">
node[~"^$"~"."]; // find nodes with empty key ("") and any value
</syntaxhighlight>

<small>NB: Overpass Turbo Wizard already has some logic in place to automatically convert ''""=""'' accordingly.</small>

==== Exists ====

The second variant selects all elements that have a tag with a certain key and an arbitrary value. It contains nothing between the key literal and the closing bracket:

<syntaxhighlight lang="cpp">
node["name"];
node['name'];
node[name];
</syntaxhighlight>

==== Not exists ====
''since v0.7.53''

This variant selects all element, that ''don't'' have a tag with a certain key and an arbitrary value.

<syntaxhighlight lang="cpp">
node[!"name"];
node[!'name'];
node[!name];
</syntaxhighlight>

In previous versions, 'not exists' had to be written as <code>node["name"!~".*"];</code>.

==== Value matches regular expression (''~'', ''!~'')====

The third variant selects all elements that have a tag with a certain key and a value that matches some regular expression. It contains after the key literal a tilde, then a second literal for the regular expression to search for:

{| class="wikitable"
! Statement
! Explanation
|-
| <code lang="cpp">node["name"~"^Foo$"];</code> || Finds nodes, where the tag ''name'' matches exactly ''Foo'' - identical to <code lang="cpp">node["name"="foo"];</code>
|-
| <code lang="cpp">node["name"~"^Foo"]; </code> || Finds nodes, where the tag ''name'' starts with ''Foo''
|-
| <code lang="cpp">node["name"~"Foo$"]; </code> || Finds nodes, where the tag ''name'' ends with ''Foo''
|-
| <code lang="cpp">node["name"~"Foo"]; </code> || Finds nodes, where the tag ''name'' contains the substring ''Foo'' anywhere in the tag value
|-
| <code lang="cpp">node["name"~".*"]; </code> || Finds nodes, where the tag ''name'' matches anything, equal to <code lang="cpp">node["name"];</code>
|-
| <code lang="cpp">node["name"!~".*"]; </code> || Finds nodes without ''name'' tag; does not have key name - identical to <code lang="cpp">node[!"name"];</code>
|-
|}

Please note that in QL you need to escape backslashes: ''["name"~"^St\."]'' results in the regular expression ''^St.'' (which finds every name starting with "St"), while ''["name"~"^St\\."]'' produces the most likely meant regular expression ''St\.'' (which finds every name starting with "St."). This is due to the C escaping rules and doesn't apply to the XML syntax.

Overpass implements the [https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended POSIX Extended] regular expression syntax.

===== Case insensitively =====

You can also search case insensitively

<syntaxhighlight lang="cpp">
node["name"~"^Foo$",i]; /* finds "foo", "FOO", "fOo", "Foo" etc. */
</syntaxhighlight>

Both the key and value variants with and without regular expressions can be negated. They then select exactly the elements which have a tag with the given key, but no matching value and the elements that don't have a tag with the given key:

<syntaxhighlight lang="cpp">
node["name"!="Foo"];
node["name"!~"Foo"];
node["name"!~"Foo",i];
</syntaxhighlight>

==== Key/value matches regular expression (~"key regex"~"value regex") ====

The fourth variant selects all elements where both key and value match a regular expression. After an initial tilde (~) the regular expression for the key needs to be provided, followed by another tilde character and eventually the regular expression for the value.

<syntaxhighlight lang="cpp">
node[~"^addr:.*$"~"^Foo$"]; /* finds addr:* tags with value exactly "Foo" */
node[~"^addr:.*$"~"^Foo"]; /* finds addr:* tags with value starting with "Foo" */
node[~"^addr:.*$"~"Foo$"]; /* finds addr:* tags with value ending with "Foo" */
node[~"^addr:.*$"~"Foo"]; /* finds addr:* tags with value containing the substring "Foo" */
node[~"^addr:.*$"~"."]; /* finds addr:* tags with any value */
node[~"^name(:.*)?$"~"."]; /* finds anything with a name or name:lang tag, and with any value */
node[~"^name(:ar|:he)?$"~"."]; /* finds anything with name, name:ar, or name:he tag, and with any value*/
</syntaxhighlight>

This format also supports case-insensitive searches: <code>node[~"^addr:.*$"~"^Foo$",i];</code>. Case-insensitivity applies to both tag key and value searches in this case.

{{Ambox
| type = notice
| text =<div style="text-align:left">
* Regular expressions for values cannot be negated in this variant. However, this can be expressed via the [[Overpass_API/Overpass_QL#Difference|difference]] block statement.
* It's not possible with this syntax to use regular expressions for matching either tag names but matching values by simpler equality or inequality.
</div>
}}

=== Bounding box{{Anchor|boundingboxqueryfilter}} ===
The ''bounding box'' query filter selects all elements within a rectangular bounding box.

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

<syntaxhighlight lang="cpp">
(south,west,north,east)
</syntaxhighlight>

It consists of an opening parenthesis. Then follow four floating point numbers, separated by commas. The filter ends with a closing parenthesis.

The floating point numbers give the limits of the bounding box: The first is the southern limit or minimum latitude. The second is the western limit, usually the minimum longitude. The third is the northern limit or maximum latitude. The last is the eastern limit, usually the maximum longitude. If the second argument is bigger than the fourth argument, the bounding box crosses the longitude of 180 degrees.

Example:

<syntaxhighlight lang="cpp">
node(50.6,7.0,50.8,7.3);
</syntaxhighlight>

See also: [[#Global bounding box (bbox)]].

=== Recurse (''n'', ''w'', ''r'', ''bn'', ''bw'', ''br'') ===

The ''recurse'' filter selects all elements that are members of an element from the input set or have an element of the input set as member, depending on the given parameter.

The input set can be changed with an adapted prefix notation. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows one of the symbols: ''w'' (forward from ways), ''r'' (forward from relations), ''bn'' (backward from nodes), ''bw'' (backward from ways), or ''br'' (backward from relations). Then follows an optional input set declaration. The filter ends with a closing parenthesis.

Examples with default input set:

<syntaxhighlight lang="cpp">
node(w); // select child nodes from ways in the input set
node(r); // select node members of relations in the input set
way(bn); // select parent ways for nodes in the input set
way(r); // select way members of relations in the input set
rel(bn); // select relations that have node members in the input set
rel(bw); // select relations that have way members in the input set
rel(r); // select relation members of relations in the input set
rel(br); // select parent relations from relations in the input set
</syntaxhighlight>

Example with modified input set:

<syntaxhighlight lang="cpp">
node(w.foo); // select child nodes from ways in the "foo" input set
</syntaxhighlight>

You can also restrict the recurse to a specific role. Just add a colon and then the name of the role before the closing parenthesis.

Examples with default input set:

<syntaxhighlight lang="cpp">
node(r:"role"); // select node members of relations in the input set
way(r:"role"); // select way members of relations in the input set
rel(bn:"role"); // select relations that have node members in the input set
rel(bw:"role"); // select relations that have way members in the input set
rel(r:"role"); // select relation members of relations in the input set
rel(br:"role"); // select parent relations from relations in the input set
</syntaxhighlight>

Example with modified input set:

<syntaxhighlight lang="cpp">
node(r.foo:"role"); // select node members with role "role" of relations in the "foo" input set
</syntaxhighlight>

And you can also search explicitly for empty roles:

<syntaxhighlight lang="cpp">
node(r:""); // select node members with empty role of relations in the input set
node(r.foo:""); // select node members with empty role of relations in the "foo" input set
</syntaxhighlight>

=== Recurse (way_cnt, way_link) ===

These variants of recurse select all nodes that are member of a specific number of way resp. way segments.
Both need a number or a range as second argument and optinally can have an input set.

The ''way_cnt'' criterion selects those nodes that are members of a given number of ways.
E.g. the criterion ''(way_cnt:2)'' selects all crossings between ways and all nodes where two ways join.

By contrast, the ''way_link'' criterion counts way segments.
Inner nodes without a crossing have way link count two,
because there is exactly one segment to connect to the predecessor and one segment to connect to the successor.
Joins also have segment count two.
This is way it is easy to select independently crossings because they have segment count three or greater
or dead ends because they have segment count one.

Examples with default input set:

<syntaxhighlight lang="cpp">
node(way_cnt:2); // select those nodes that are members of exactly two of the given ways
node(way_cnt:3-4); // select those nodes that are members of three to four of the given ways
node(way_cnt:2-); // select those nodes that are members of two or more of the given ways
node(way_link:1); // select those nodes that are members of exactly one segment of the given ways, i.e. are dead ends
node(way_link:4-5); // select those nodes that are members of four to five segments of the given ways
node(way_link:3-); // select those nodes that are members of three or more segments of the given ways, i.e. crossings
</syntaxhighlight>

Example with modified input set:

<syntaxhighlight lang="cpp">
node(way_link.foo:3-); // select those crossing nodes based on the way grid in set foo
</syntaxhighlight>

=== By input set (''.setname'') ===

The "item" filter selects all elements from its input set.

As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of a dot, followed by the name of the input set.

Examples: The default set:
<syntaxhighlight lang="cpp">
node._;
</syntaxhighlight>
and a named set:
<syntaxhighlight lang="cpp">
node.a;
</syntaxhighlight>

It is also possible to specify several input sets ('''[[#Intersection|set intersection]]'''). For example:
<syntaxhighlight lang="cpp">
node.a.b;
</syntaxhighlight>
: This statement returns all nodes which are '''both''' in input set ''.a'' and input set ''.b''.

=== By element id ===

The ''id-query'' filter selects the element of given type with given id. It supports beside the OSM datatypes node, way, and relation also the type area.

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows a positive integer. The filter is ended with a closing parenthesis.

Examples:
<syntaxhighlight lang="cpp">
node(1);
way(1);
rel(1);
area(1);
</syntaxhighlight>

Area ids are derived from an existing OSM relation by adding 3600000000. There used to be a similar formula for ways, but closed ways can now directly used as areas. You should use the [[Overpass API/Overpass QL#Map way.2Frelation to area .28map to area.29|map_to_area function]] to avoid having to make these calculations manually and depend on any hard-coded constants in your query.

Area creation is subject to some extraction rules, i.e. not all ways/relations have an area counterpart. See [https://github.com/drolbr/Overpass-API/blob/master/src/rules/areas.osm3s areas.osm3s] for details.

Since version 0.7.54, the ''id-query'' filter also supports multiple values. To avoid conflicts with the bounding box filter, a new mandatory ''id:'' prefix has to be used in this case.

<syntaxhighlight lang="cpp">
node(id:1000,1001,1002,1003,1004,1005);
way(id:3998029,3998240,4065354,4065364,4065392,4065421);
rel(id:10815,10816);
area(id:1234);
</syntaxhighlight>

'''Performance hint:''' Try to bundle multiple id queries into one statement, i.e. instead of writing <code>(way(3998029);way(3998240);way(4065354););</code> use <code>way(id:3998029,3998240,4065354);</code>

=== Relative to other elements (''around'') ===
{{Ambox|text=When possible, consider using the ''[[#boundingboxqueryfilter|bounding box]]'' query filter instead of the ''around'' query filter. The bounding box query filter performs faster.|type=notice}}
The ''around'' filter selects all elements within a certain radius in metres around the elements in the input set. If you provide coordinates, then these coordinates are used instead of the input set. The input set can be changed with an adapted prefix notation. As for all filters, the result set is specified by the whole statement, not the individual filter.

A radius of 0 can be used for a way intersection test on outer/inner points.

Syntax: It consists of an opening parenthesis. Then follows the keyword <code>around</code>. Then follows optionally an input set declaration. Then follows a single floating point number that denotes the radius in meters. The filter either ends with a closing parenthesis or is followed by two comma separated floating point numbers indicating latitude and longitude and then finally a closing parenthesis.

<syntaxhighlight lang="cpp">
(around[.input_set]:radius)
(around:radius,latitude,longitude)
</syntaxhighlight>

Since version 0.7.55, it is possible to query for all elements which are within a certain radius of a given linestring, which is given by a list of lat/lon pairs:

<syntaxhighlight lang="cpp">
(around[.input_set]:radius)
(around:radius,latitude_1,longitude_1,latitude_2,longitude_2,...,latitude_n,longitude_n)
</syntaxhighlight>

Example:
<syntaxhighlight lang="cpp">
node(around:100.0);
way(around:100.0);
rel(around:100.0);
</syntaxhighlight>

Example with modified input set:
<syntaxhighlight lang="cpp">
node(around.a:100.0);
</syntaxhighlight>

Example with coordinates:
<syntaxhighlight lang="cpp">
node(around:100.0,50.7,7.1);
way(around:100.0,50.7,7.1);
rel(around:100.0,50.7,7.1);
</syntaxhighlight>

Example with linestring:

{{OverpassTurboExample|loc=50.51201;8.09641;12|query=
way[highway](around:500,50.540853270068986,8.048780365649707,50.53106288705902,8.030823236553783,50.51780737956311,8.019643105996508,50.50287491071276,8.016749912560886,50.48828159051387,8.022534398052139,50.47599950382573,8.036215335651725,50.467689755650376,8.055945038928135,50.46447690759688,8.079058902127825,50.46679590711731,8.102435269947343,50.47433280529453,8.122917034379736,50.48606755168466,8.137738019645033,50.50041288059356,8.144896569557243,50.51542994506574,8.143425882283827,50.529090915610794,8.13352458229042,50.53955268865336,8.11652989500613,50.545404823255616,8.09473704711951,50.545858734919165,8.07108928349599,50.540853270068986,8.048780365649707)
;(._;>;);out meta;
}}

For further use cases, see this [https://www.openstreetmap.org/user/mmd/diary/42055 diary entry].

Example: Find all cinema nodes in Bonn which are at most 100m away from bus stops
{{OverpassTurboExample|query=
area[name="Bonn"];
node(area)[highway=bus_stop];
node(around:100)[amenity=cinema];
out;
}}

Find both cinema nodes and ways in Bonn, which are at most 100m away from bus stop nodes:
{{OverpassTurboExample|query=
area[name="Bonn"];
node(area)[highway=bus_stop]->.bus_stops;
(
way(around.bus_stops:100)[amenity=cinema];
node(around.bus_stops:100)[amenity=cinema];
);
(._;>;);
out meta;
}}

=== By polygon (''poly'') ===
The ''polygon'' filter selects all elements of the chosen type inside the given polygon.

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows the keyword ''poly''. Then follows a string containing an even number of floating point numbers, divided only by whitespace. Each pair of floating point numbers represents a coordinate, in order latitude, then longitude. The filter ends with a closing parenthesis:
<syntaxhighlight lang="cpp">
(poly:"latitude_1 longitude_1 latitude_2 longitude_2 latitude_3 longitude_3 …");
</syntaxhighlight>

An example (a triangle near Bonn, Germany):
<syntaxhighlight lang="cpp">
node(poly:"50.7 7.1 50.7 7.2 50.75 7.15");
way(poly:"50.7 7.1 50.7 7.2 50.75 7.15");
rel(poly:"50.7 7.1 50.7 7.2 50.75 7.15");
</syntaxhighlight>

'''Performance hint:''' A large number of latitude/longitude pairs slows down the <code>(poly: )</code> filter, hence simplifying the polyline geometry before using it in a poly filter is recommended.

=== ''newer'' ===
The ''newer'' filter selects all elements that have been changed since the given date. As opposed to other filters, this filter cannot be used alone. If the underlying database instance supports attic data and the date difference is at most one month, then "changed" is probably a better choice than "newer".

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows a date specification. Please note that this date specification cannot be abbreviated and has to be put in single or double quotes. The filter ends with a closing parenthesis.

Example:
<syntaxhighlight lang="cpp">
node._(newer:"2012-09-14T07:00:00Z");
</syntaxhighlight>
: This finds all nodes that have changed since 14 Sep 2012, 7 h UTC, in the given input set.

=== By date of change (''changed'') ===

The ''changed'' filter selects all elements that have been changed between the two given dates. If only one date is given, then the second is assumed to be the front date of the database.
If only one date is given and it is run with the current timestamp, then it behaves exactly like "newer" with two exceptions: first, it is faster (see note), second, it can also stand as the only filter.

'''Note:''' As of June 2017, a known bug can cause "changed" to be much slower than "newer" in some cases. Consider using "newer" until it is resolved, or consider testing which one runs faster for you. See the following Github issues: [https://github.com/drolbr/Overpass-API/issues/278 <s>#278</s>] (resolved), [https://github.com/drolbr/Overpass-API/issues/322 #322], [https://github.com/drolbr/Overpass-API/issues/346 #346]. See this [https://forum.openstreetmap.org/viewtopic.php?pid=649744#p649744 discussion] too.

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows a date specification. Please note that this date specification cannot be abbreviated and has to be put in single or double quotes. Then can follow a comma and a second date specification. The filter ends with a closing parenthesis.

Example: All changes since the given date and now
<syntaxhighlight lang="cpp">
node._(changed:"2012-09-14T07:00:00Z");
</syntaxhighlight>

Example: All changes between the two given dates
<syntaxhighlight lang="cpp">
node._(changed:"2012-09-14T07:00:00Z","2012-09-14T07:01:00Z");
</syntaxhighlight>

=== By user (''user'', ''uid'') ===
The ''user'' filter selects all elements that have been last touched by the specified user.

It has no input set. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows either the keyword ''user'', a colon and a string literal denoting the user name to search for. Or the keyword ''uid'' followed by the user id of the user to search for. The filter ends with a closing parenthesis.

Example:
<syntaxhighlight lang="cpp">
node(user:"Steve");
node(uid:1);
</syntaxhighlight>

For all elements ever touched by a user use ''user_touched'' or ''uid_touched'':

<syntaxhighlight lang="cpp">
node(user_touched:"Steve");
node(uid_touched:1);
</syntaxhighlight>

Since release 0.7.53 it is also possible to specify multiple user names:
<syntaxhighlight lang="cpp">
node(user:"Mapper1","Mapper2","Mapper 3");
node(uid:1,2,4,8,16);
</syntaxhighlight>

=== By area (''area'') ===
The ''area'' filter selects all elements of the chosen type that are inside the given area or areas.
Please note with regard to attic data that areas derived from relations always represent current data.

The input set can be changed with an adapted prefix notation. As for all filters, the result set is specified by the whole statement, not the individual filter.

Syntax: It consists of an opening parenthesis. Then follows the keyword ''area''. Then can follow a colon and a non-negative integer. The filter ends with a closing parenthesis.

Nodes are found if they are properly inside or on the border of the area.
Ways are found if at least one point (also points on the segment) is properly inside the area.
A way ending on the border and not otherwise crossing the area is not found.
Relations are found if one of its members is properly inside the area.

If the area statement is provided without integer, the areas from the input set are used. An example:
<syntaxhighlight lang="cpp">
node(area);
way(area);
rel(area);
</syntaxhighlight>

The example with modified input set:
<syntaxhighlight lang="cpp">
node(area.a);
way(area.a);
rel(area.a);
</syntaxhighlight>

If an integer is added, the input set is ignored and instead the area that has the given integer as id is taken. For example:
<syntaxhighlight lang="cpp">

// NOTE: 2400xxx AREA IDS FOR WAYS ARE NO LONGER SUPPORTED SINCE RELEASE 0.7.57
// use closed ways directly instead

node(area:2400000001);
way(area:2400000001);
rel(area:2400000001);
</syntaxhighlight>

'''Caveat''': ''' ''area(area);'' is currently not supported'''. In this case, the (area) filter will be silently ignored, leading to unexpected results.

Because areas in OSM are not native elements but are only inferred from the OSM database using its closed ways or relations; this facility allows grouping their various representation in a coherent set which can store their geometry, independently of their complexity and representation in the OSM database, as if they were a single distinctive element, without using complex filtering rules in your query. However associating these objects with an OSM id attribute requires some adjustment because the same id value could be used for unrelated elements with different type (way or relation). For this reason, areas returned by the Overpass API only have a "virtual" id specific to the Overpass API, but not found directly in the OSM database.

By convention the area id can be calculated from an existing OSM relation by adding 3600000000 respectively. Note that area creation is subject to some extraction rules, i.e. not all relations have an area counterpart (notably those that are tagged with {{Tag|area||no}}, and most multipolygons and that don't have a defined {{Tag|name}} will not be part of areas).

Areas are created by a regular job on the Overpass API server and usually have a lag of several hours compared to the OSM main database. The exact timestamp can be determined by checking the `timestamp_areas_base` value in the Overpass json or xml result.

If you want more immediate results (not depending on the delayed batch processing), you can also write your own filters without using this facility in your Overpass query: use standard OSM element types and ids and filter them by specific tags of your choice.

: See [https://github.com/drolbr/Overpass-API/blob/master/src/rules/areas.osm3s areas.osm3s] for details of the filters (written using the XML variant of the Overpass query language) currently by Overpass used to generate the areas that can be queried with this facility. Those areas are defined using the "pivot" query feature (see below).

=== Area pivot (''pivot'') ===
The ''pivot'' filter selects the element of the chosen type that defines the outline of the given area.

The input set can be changed with an adapted prefix notation. As for all filters, the result set is specified by the whole statement, not the individual filter.

It consists of an opening parenthesis. Then follows the keyword <code>pivot</code>. The filter ends with a closing parenthesis.

The statement finds for each area in the input set the respective element that the area has been generated from.
Derived areas are derived from relations.
Closed way represent themselves and are therefore passed from the input set to the output set.

Examples:
<syntaxhighlight lang="cpp">
// These use the default input set '_'
way(pivot);
rel(pivot);
// These use the input set 'a'
way(pivot.a);
rel(pivot.a);
</syntaxhighlight>

The following example determines the area(s) for the county of Greater London, and stores the result in the set <code>londonarea</code>. In the next statement, the areas contained in the <code>londonarea</code> set are converted back into their corresponding OSM relations using the <code>pivot</code> filter. Finally, <code>out geom;</code> outputs the relations (including their child ways and nodes).<syntaxhighlight lang="cpp">
area[name="London"][admin_level=6][boundary=administrative]->.londonarea;
rel(pivot.londonarea);
out geom;
</syntaxhighlight>

=== Conditional query filter ''(if:)'' ===
''since v0.7.54''

The query filter can be added as condition to a query statement. It has an [[#Evaluators|evaluator]] as argument and it lets pass only those elements for which the expression returns boolean true.

At the moment, the query filter cannot be the only condition in a query. This is due to implementation reasons and will change in future versions.

It is technically possible to have multiple query filters in a single query. But it does not make sense:
* Their evaluators can be combined with a conjunction in a single query filter.
* This has the same semantics and is faster.

Its syntax is:
(if: <Evaluator>)
The whitespace is optional.

Many filters above can be generalized using conditional query filter, if one needs more specific conditions for filter the objects in the query input set. For example, the query:
<syntaxhighlight lang="cpp">
node[name=foo];
</syntaxhighlight>
is equivalent to the following one using a conditional query filter (but for simplicity the former syntax using simpler a filter by tag value is still recommended, as it ''may'' have better performance on the Overpass server, and because the new syntax for evaluators ''may'' still not be supported in the current implementation of Overpass servers and client libraries before version 0.7.54 of the API):
<syntaxhighlight lang="cpp">
node(if: t["name"] == "foo");
</syntaxhighlight>


== Evaluators ==
Evaluators are building blocks that yield on execution a value.
The use of which of the evaluators makes sense depends on the context.

Evaluators help to filter for elements within a query statement.
They allow to get statistical information about query results.
And they allow to remove or add tags from elements.

Currently only tag evaluators are supported.
Geometry evaluators are planned but not implemented in this version.

The following types of evaluators exist and are explained further down:
* Const evaluators deliver always the same value independent of context.
* Element dependent evaluators deliver information about an individual object.
They only make sense in the context of a single element.
* Statistical evaluators deliver information about a set as a whole.
* Aggregators let an element dependent evaluator loop over all elements of a set and combine its results.
* Operators and endomorphisms combine the result of one or two evaluator executions into a new result.

<span style="color:blue">'''''TODO:'''''</span>
* '''''Need to add simple examples for each section, similar to e.g. regular expressions before.'''''
* '''''Merge some of the very simple explanations in the blog posts back into this document.'''''

=== Literals ===

Literals represent fixed values, and can be used for comparisons and tests against operators, and as arguments to evaluators. Examples of literals:
{| class="wikitable"
! Literal
! Explanation
|-
| <code lang="cpp">3</code> || The whole number value 3 †*
|-
| <code lang="cpp">3.14159 </code> || The floating point number 3.14159 †*
|-
| <code lang="cpp">2017-09-28T19:51:44Z</code> || An [https://en.wikipedia.org/wiki/ISO_8601 ISO 8601] timestamp, in the format in common use in the OpenStreetMap database.
The format is <code lang="cpp">YYYY-MM-DDThh:mm:ssZ</code>. ‡
|-
| <code>London Bridge</code> || A string of characters ‡
|-
| <code lang="cpp">addr:housenumber </code> || A string representing a commonly used OpenStreetMap key, [https://taginfo.openstreetmap.org/keys/addr%3Ahousenumber addr:housenumber] ‡
|}
† Integers and floating point numbers treated as numbers and expressed as less than zero (e.g -1.3) ''are not themselves literals''. They are literals modified with the [[Overpass QL#Unary Minus|unary minus]] operator.

<nowiki>*</nowiki> Some positive and negative integer and floating point numbers, (such as when used in the context of the [[Overpass QL#Bounding box|bounding box query filter]]), are interpreted as strings.

‡ It is generally wise to include quotes around these literals, to avoid the possibility of characters like <code>: -</code> or whitespace being incorrectly interpreted by an evaluator. For example, <code>"London Bridge"</code> and <code>"addr:housenumber"</code> avoids parsing issues inside tag evaluators. <code lang="cpp">"2017-09-28T19:51:44Z"</code> is a safe way to write a timestamp literal.

Some functions, such as <code>date()</code>, will attempt to [https://en.wikipedia.org/wiki/Type_conversion type cast] a literal into a standard format suitable for Overpass QL.


=== Fixed Value evaluator ===

This operator always returns a fixed value.
It does not take any argument.

Its syntax is

<Value>

=== Element Dependent Operators ===

Element dependent operators depend on one or no parameter.
Their syntax varies, but most have the appearance of a function name plus parentheses.

They can only be called in a context where elements are processed.
This applies to convert, to filter, or to arguments of aggregate functions.
They cannot be called directly from make.

==== Id and Type of the Element ====

The operator ''id'' returns the id of the element.
The operator ''type'' returns the type of the element.
Both operators take no parameters.

The syntax is

id()

resp.

type()

=== Tag Value and Generic Value Operators ===

The tag operator returns the value of the tag of the given key.
The ''is_tag'' operator returns "1" if the given element has a tag with this key and "0" otherwise.
They only can be called in the context of an element.

Their syntax is

t[<Key name>]

resp.

is_tag(<Key name >)

The <Key name> must be in quotation marks if it contains special characters.

The tag operator can also be called with a substatement. Its syntax is then

t[<Substatement>]

The generic tag operator returns the value of the tag of the key it is called for.
It only can be called in the context of an element.
In addition, it must be part of the value of a generic property to have its key specified.

Its syntax is

::

=== All Keys Evaluator ===

The all keys evaluator returns a container of the keys of the given element.

Its syntax is

keys()


=== Meta Data Operators ===

The ''version'' operator returns the version number of the given element.
Its syntax is:

version()

The ''timestamp'' operator returns the timestamp of the given element.
Its syntax is:

timestamp()

The ''changeset'' operator returns the changeset id of the changeset
in which the given element has been last edited.
Its syntax is:

changeset()

The ''uid'' operator returns the id of the user
that has last touched the given element.
Its syntax is:

uid()

The ''user'' operator returns the name of the user
that has last touched the given element.
Its syntax is:

user()

=== Element Properties Count ===
''since v0.7.55''

This variant of the ''count'' operator counts tags or members
of the given element.
Opposed to the statistical variant of the count operator,
they cannot take an input set as extra argument.

The syntax for tags is

count_tags()

The syntax to count the number of member entries is

count_members()

The syntax to count the number of distinct members is

count_distinct_members()

The syntax to count the number of member entries with a specific role is

count_by_role(<Evaluator>)

The syntax to count the number of distinct members with a specific role is

count_distinct_by_role(<Evaluator>)

=== Per Member Aggregators ===

Aggregators per member help to process information that does apply to only a single member of a way or relation.
Examples of this are the position within the way or relation, geometric properties like the angles, or roles.
A per member aggregator needs an element to operate on and executes its argument multiple times,
passing the possible positions one by one in addition to the element to its argument.

==== Per Member ====
''since v0.7.56''

For each element, the aggregator executes its argument once per member of the element.
The return value is a semicolon separated list of the return values.
No deduplication or sorting takes place.
Note that the aggregator returns an empty value for nodes and deriveds
and does not execute its argument in that case.

The syntax is

per_member(<Evaluator>)

==== Per Vertex ====
''since v0.7.56''

For each element, the aggregator executes its argument once per (inner) vertex of the element.
Otherwise it behaves similar to the per_member operator.
For closed ways, this means that it is executed once for all vertices but the first member.
For open ways, it is executed once for all vertices but the first and last member.
For relations its behaviour is currently undefined.

The syntax is

per_vertex(<Evaluator>)

=== Member Dependent Functions ===

Member dependent functions can only be used when an element plus a position within the element is in context.
They then deliver specific information for that member.

==== Position of the Member ====
''since v0.7.56''

The position function returns for a member its one-based position within the element.

The syntax is

pos()

==== Reference to the Member ====
''since v0.7.56''

The functions mtype and reference return for a member the type resp. id of the referenced object.

The syntax is

mtype()

resp.

ref()

==== Role of the Member ====
''since v0.7.56''

The role function returns the role of the member.

The syntax is

role()

==== Angle of a Way at the Position of a Member ====
''since v0.7.56''

This function returns the angle between the segment ending at this member and the segment starting there.
It is so far only defined for ways.
If the way is a closed way then for the last member the first segment is used as the starting segment.
This function is intended to be used within the per_vertex() enumerator.

The syntax is

angle()

=== Geometry Related Operators ===

==== Closedness ====
''since v0.7.55''

The operator ''is_closed'' returns whether the element is a closed way.
The operator is undefined for any other type of element.
For ways, it returns "1" if the first member of the way is equal to the last member of the way
and "0" otherwise.
The operators takes no parameters.

The syntax is

is_closed()

Example: Find all Danish roundabouts that are not closed circles

<syntaxhighlight lang="cpp">
area["ISO3166-1"="DK"][admin_level=2];
way["junction" = "roundabout"](area)
(if: is_closed() == 0);
</syntaxhighlight>

==== Geometry ====
''since v0.7.55''

The ''geometry'' operator returns the geometry of a single object
as a geometry that can be put into the other geometry converting operators.

Its syntax is:

geom()

==== Length ====
''since v0.7.55''

The length operator returns the length of the element in meters.
For ways this is the length of the way.
For relations this is the sum of the lengths of the members of type way.
For nodes it is always zero.

Its syntax is:

length()

==== Latitude and Longitude ====
''since v0.7.56''

The latitude and longitude operators return the respective coordinate of the element or the element's center.
For nodes it is the latitude resp. longitude of the node's coordinate.
For ways and relations it refers to the coordinate derived from the center of the bounding box.

Their syntaxes are:

lat()

resp.

lon()

=== Point evaluator ===
''since v0.7.55''

The ''point evaluator,'' syntax <code>pt(<latitude>, <longitude>)</code>'','' returns a valid OpenStreetMap node geometry. The geometry returned is a node at the latitude and longitude derived from the two given values. Each user supplied value, <code>latitude</code> and <code>longitude</code>, should parse as a valid floating point number.
* <code>latitude</code> must fall within the range of -90 to 90, inclusive. Digits beyond 10e<sup>-7</sup> (which is beyond the accuracy OpenStreetMap saves a node in) are ignored if within this range.
* <code>longitude</code> must fall within the range of -180 to 180, inclusive. Digits beyond 10e<sup>-7</sup> (which is beyond the accuracy OpenStreetMap saves a node in) are ignored if within this range.

=== Linestring evaluator ===
''since v0.7.55''

This operator always returns a geometry.
The geometry is a line made of the points that are supplied as arguments.

Its syntax is

lstr(<Evaluator>, <Evaluator>[, ...])


=== Polygon evaluator ===
''since v0.7.55''

This operator always returns a geometry.
The geometry is a polygon made of the linestrings that are supplied as arguments.
The polygon adheres to the right hand rule and has no self-intersections.

Its syntax is

poly(<Evaluator>, <Evaluator>[, ...])

=== Aggregators ===

Aggregators need for execution both a set to operate on and an evaluator as argument.
That evaluator will loop over each element of the set, and the aggregator will combine its results.

==== Union and Set ====

These two aggregation functions execute their evaluators on each element of a specified set, returning a text value.
The basic syntax is:

<Set>.u(<Evaluator>)

<Set>.set(<Evaluator>)

For the default set ''_'' the set parameter can be left off:

u(<Evaluator>)

set(<Evaluator>)

''set'' returns a semi-colon separated list of all distinct values that appear.

''u'' is meant to operate on sets returning a single unique value such as sets with only one member. If only one value is found, then that value is returned. If no value is found then ''u'' returns an empty string. If multiple different values are found then ''u'' returns the text "< multiple values found >".

==== Min and Max ====

The basic syntax is

<Set>.min(<Evaluator>)

resp.

<Set>.max(<Evaluator>)

If the set is the default set ''_'' then you can drop the set parameter:

min(<Evaluator>)

resp.

max(<Evaluator>)

These two evaluators execute their right hand side evaluators on each element of the specified set.
If all return values are valid numbers then ''min'' returns the minimal amongst the numbers.
Likewise, if all return values are valid numbers then ''max'' returns the maximal amongst the numbers.
If not all return values are valid numbers then ''min'' returns the lexicographically first string.
Likewise, if not all return values are valid numbers then ''max'' returns the lexicographically last string.
If no value is found then each ''min'' and ''max '' return an empty string.

==== Sum ====

The basic syntax is

<Set>.sum(<Evaluator>)

If the set is the default set ''_'' then you can drop the set parameter:

sum(<Evaluator>)

This evaluator executes its right hand side evaluators on each element of the specified set.
If all return values are valid numbers then ''sum'' returns their sum.
If not all return values are valid numbers then ''sum'' returns "NaN".

=== Statistical Count ===

This variant of the ''count'' operator counts elements of a given type in a set.

The syntax variants

count(nodes)
count(ways)
count(relations)
count(deriveds)
count(nwr)
count(nw)
count(wr)
count(nr)

counts elements in the default set ''_'', and the syntax variant

<Set>.count(nodes)
<Set>.count(ways)
<Set>.count(relations)
<Set>.count(deriveds)
<Set>.count(nwr)
<Set>.count(nw)
<Set>.count(wr)
<Set>.count(nr)

counts elements in the set &lt;Set&gt;.

=== Union of Geometry ===
''since v0.7.55''

The basic syntax is

<Set>.gcat(<Evaluator>)

If the set is the default set ''_'' then you can drop the set parameter:

gcat(<Evaluator>)

The evaluator executes its right hand side evaluator on each element of the specified set.
It then combines the obtained geometries in one large object.
If geometries are contained multiple times in the group
then they are as well repeated as members of the result.

=== Unary Operators ===

Unary operators need for execution an operand.
They are always written in prefix notation.
The operators can be grouped with parentheses:
The two variants

<Operator><Evaluator>

and

(<Operator><Evaluator>)

have as standalone expressions precisely the same semantics.
The parenthesis variant exists to override operator precedence.

The order of precedence is as follows, ordered weak to strong binding:
* logical disjunction
* logical conjunction
* equality, inequality
* less, less-equal, greater, greater-equal
* plus, binary minus
* times, divided
* logical negation
* unary minus

In the following, the operators are ordered by precedence, stronger binding last.

==== Boolean Negation ====

The boolean negation evaluates to "1" if its argument evaluates to a representation of boolean false.
Otherwise it evaluates to "0".
Representations of boolean false are the empty std::string and every std::string that is a numerical representation of zero.
Every other std::string represents boolean true.

Its syntax is

! <Evaluator>

The whitespace is optional.

==== Unary minus ====

The unary minus operator negates its argument.
If the argument is an integer or a floating point number then it is negated as integer resp. floating point number.
Otherwise the unary minus operator returns "NaN".

The syntax for unary minus is:

- <Evaluator>

The whitespace is optional.

=== Binary Operators ===

Binary operators need for execution two operands.
They are always written in infix notation.
The operators can be grouped with parentheses:
The two variants

<Evaluator><Operator><Evaluator>

and

(<Evaluator><Operator><Evaluator>)

have as standalone expressions precisely the same semantics.
The parenthesis variant exists to override operator precedence:

2 + 3 * 4

is evaluated to ''2 + 12'', then finally ''14''.

(2 + 3) * 4

is evaluated to ''5 * 4'', then finally ''20''.

The order of precedence is as follows, ordered weak to strong binding:
* the ternary operator
* logical disjunction
* logical conjunction
* equality, inequality
* less, less-equal, greater, greater-equal
* plus, binary minus
* times, divided
* logical negation
* unary minus

In the following, the operators are ordered by precedence, stronger binding last.

==== Boolean Disjunction ====

The boolean disjunction evaluates to "1" if one or both of its arguments evaluate to a representation of boolean true.
Otherwise it evaluates to "0".
Representations of boolean false are the empty string and every string that is a numerical representation of zero.
Every other string represents boolean true.
Currently, both arguments are always evaluated.
This may change in future versions.

Its syntax is

<Evaluator> || <Evaluator>

The whitespace is optional.

==== Boolean Conjunction ====

The boolean conjunction evaluates to "1" if both of its arguments evaluate to a representation of boolean true.
Otherwise it evaluates to "0".
Representations of boolean false are the empty string and every string that is a numerical representation of zero.
Every other string represents boolean true.
Currently, both arguments are always evaluated.
This may change in future versions.

Its syntax is

<Evaluator> && <Evaluator>

The whitespace is optional.

==== Equality and Inequality ====

The equaliy operator evaluates to "1" if both of its arguments are equal.
Otherwise it evaluates to "0".
The inequality operator evaluates to "0" if both of its arguments are equal.
Otherwise it evaluates to "1".
If both arguments can be interpreted as integers then the represented values are compared.
Otherwise, if both arguments can be interpreted as floating point numbers then the represented values are compared.
In all other cases the arguments are treated as strings.

Its syntax is for equality

<Evaluator> == <Evaluator>

and for inequality

<Evaluator> != <Evaluator>

The whitespace is optional.

==== Less, Less-Equal, Greater, and Greater-Equal ====

These operators evaluate to "1" if their arguments compare respectively.
Otherwise they evaluate to "0".
If both arguments can be interpreted as integers then the represented values are compared.
Otherwise, if both arguments can be interpreted as floating point numbers then the represented values are compared.
In all other cases the arguments are treated as strings.

The syntaxes for less, less-equal, greater, and greater-equal in this order are

<Evaluator> < <Evaluator>

<Evaluator> <= <Evaluator>

<Evaluator> > <Evaluator>

<Evaluator> >= <Evaluator>

The whitespace is optional.

==== Plus and Minus ====

While both operators have the same priority, they accept different kinds of arguments.
If the arguments are both integers then they are added resp. subtracted as integers.
If the arguments are both floating point numbers then they are added resp. subtracted as floating point numbers.
Otherwise the plus operator concatenates the arguments as strings.
Opposed to this, the minus operator returns "NaN".

The unary minus is an operator distinct from the binary minus operator defined here.
It has a higher priority.

The syntaxes for plus and minus in this order are

<Evaluator> + <Evaluator>

<Evaluator> - <Evaluator>

The whitespace is optional.

==== Times and Divided ====

The times operator and the divided operator perform the respective arithmetic operations.
If the arguments are both integers then they are multiplied as integers.
Otherwise, if the arguments are both floating point numbers then they are multiplied resp. divided as floating point numbers.
Division does treat integers like floating point numbers.
If one or both arguments are no numbers then both the operators return "NaN".

The syntaxes for plus and minus in this order are

<Evaluator> * <Evaluator>

<Evaluator> / <Evaluator>

The whitespace is optional.

=== The Ternary Operator ===

The ternary operator needs for execution three operands.
If the first operand evaluates to boolean true
then it evaluates to what the second operand evaluates.
Otherwise it evaluates to what the third operand evaluates.

The two variants

<Evaluator>?<Evaluator>:<Evaluator>

and

(<Evaluator>?<Evaluator>:<Evaluator>)

have as standalone expressions precisely the same semantics.
The parenthesis variant exists to override operator precedence.
For the precendence, see the binary operators.

=== String Endomorphisms ===

String endomorphisms are functions with one argument.
Many of them help to normalize or check the value of its argument.
They always first let their argument be evaluated.
Their syntax is always

<Function Name>(<Evaluator>)

==== Number Check, Normalizer and Suffix ====

The function ''number'' turns its argument into a number.
If its argument starts with a number then ''number'' returns that number in a normalized format.
Otherwise it returns "NaN".
The function ''is_number'' checks whether its argument starts with a number.
It returns "1" if its argument can be parsed as a number and "0" otherwise.
The function ''suffix'' returns the suffix if any after the number in its argument.
If the argument does not start with a number then it returns the empty string.

Their syntaxes are

number(<Evaluator>)

resp.

is_number(<Evaluator>)

resp.

suffix(<Evaluator>)

==== Number Manipulation ====
''since v0.7.58''

The function ''abs'' interprets its argument as a number and returns its absolute value.

Its syntax is

abs(<Evaluator>)

==== Date Check and Normalizer ====

The function ''date'' turns its argument into a number representing a date.
If its argument is a date then ''date'' returns the number representing its argument's value.
Otherwise it returns "NaD". The return value can be used for comparison operations only, it
can't be used for any kind of calculations (e.g. time differences).

The function ''is_date'' checks whether its argument represents a date.
It returns "1" if its argument can be parsed as a date and "0" otherwise.

A string is parsed for a date as follows:
* the first group of digits is understood as year
* the next group of digits if present is understood as month
* then the next group if present is understood as day
* if more groups of digits are present then they are understood as hour, minute, second
To be a date the year must be bigger than 1000,
the month if present less or equal 12,
the day if present less or equal 31,
the hour if present less or equal 24,
and the minute and second if present less or equal 60.

The date parser may get more liberal in future versions and accept more representations of dates.

The functions' syntax is

date(<Evaluator>)

resp.

is_date(<Evaluator>)

=== Geometry Endomorphisms ===

Geometry endomorphisms are functions with one argument.
Many of them help to normalize or check the value of its argument.
They always first let their argument be evaluated.
Their syntax is always

<Function Name>(<Evaluator>)

==== Center ====
''since v0.7.55''

The function ''center'' returns the center of its argument.
It expects a function that evaluates to a geometry.
It then delivers the point that is at the center of the bounding box of the geometry.

Its syntax is

center(<Evaluator>)

==== Trace ====
''since v0.7.55''

The function ''trace'' returns the trace of its argument.
It expects a function that evaluates to a geometry.
It then delivers a collection of all segments and nodes that appear in its input.
Ways are split at points that are explicitly in the set
and at points that belong to more than one way in the set.
Every node and segment is contained at most once.

Its syntax is

trace(<Evaluator>)

==== Hull ====
''since v0.7.55''

The function ''hull'' returns the convex hull of its argument.
It expects a function that evaluates to a geometry
It then delivers a polygon without holes that contains all of its arguments.

Its syntax is

hull(<Evaluator>)



=== List Represented Set Operators ===

Sometimes there is a need to represent multiple values in a tag's value.
Although by no means mandated by the data format,
the de-facto solution is
to represent a set of values by a a semi-colon separated list of those values.

This section offers some functions to make handling of these lists easier.
Currently, the delimiter is hard-coded to a semi-colon.
For the sake of simplicity,
leading or trailing white space at each list entry is ignored.

Note also that the lists are understood as sets.
This means that the order of list elements does no matter.

==== List Represented Set Theoretic Operators ====

===== lrs_in =====
''since v0.7.55''

The function ''lrs_in'' returns "1"
if its first argument is contained in the second argument treated as set.
It returns "0" otherwise.

The function's syntax is

lrs_in(<Evaluator>, <Evaluator>)

===== lrs_isect =====
''since v0.7.55''

The function ''lrs_isect'' returns the intersection of its two arguments treated as sets.
If the arguments have no values in common then the empty string is returned.

The function's syntax is

lrs_isect(<Evaluator>, <Evaluator>)

===== lrs_union =====
''since v0.7.55''

The function ''lrs_union'' returns the union of its two arguments treated as sets.

The function's syntax is

lrs_union(<Evaluator>, <Evaluator>)

==== List Represented Set Statistic Operators ====

===== lrs_min =====
''since v0.7.55''

The function ''lrs_min'' returns the minimum of the elements in its argument treated as set.
If all entries are numbers then the comparsion is numerical.

The function's syntax is

lrs_min(<Evaluator>)

===== lrs_max =====
''since v0.7.55''

The function ''lrs_max'' returns the maximum of the elements in its argument treated as set.
If all entries are numbers then the comparsion is numerical.

The function's syntax is

lrs_max(<Evaluator>)

=== Set Key-Value Evaluator ===

Sets can have not only members.
The may get assigned properties by other statements.

An example is the property "val":
This property contains inside a "for"-loop the respective value of the current loop.

The syntax is

<Set>.<Property>

As opposed to most other situations, it is mandatory to explicitly state the set.

== Special syntax ==
=== Comments ===
Overpass QL allows comments in the same style of C, C++, Javascript, or CSS source code:

<syntaxhighlight lang="cpp">
out; // A single line comment
/* Comments starting with slash asterisk must always be closed with an asterisk slash. */
/* But they can span
multiple lines. */
</syntaxhighlight>

=== Extended Overpass Turbo Queries ===
[[Overpass turbo/Extended Overpass Turbo Queries|''Extended Overpass Turbo Queries'']] are not part of the Overpass QL language specification. However, Overpass QL is a core component of code generated by the [[Overpass turbo/Wizard|Overpass Turbo Query Wizard]], and knowing about the shortcuts Extended Overpass Turbo Queries provide is useful when querying an Overpass Turbo server. It is likely that you will at some point run into this syntax when viewing examples of Overpass Turbo queries.

Extended Overpass Turbo Queries may be identified by double braces, <code><nowiki>{{ }}</nowiki></code>. For a full list of these queries and their purposes, see [[Overpass turbo/Extended Overpass Turbo Queries|Extended Overpass Turbo Queries]].

=== Escaping ===
The following C-style escape sequences (also defined in Javascript) for representing characters are recognized:

* <code style="background:#F8F8F8;color:#000">\n</code> escapes a newline
* <code style="background:#F8F8F8;color:#000">\t</code> escapes a tabulation
* <code style="background:#F8F8F8;color:#000">\"</code> or <code style="background:#F8F8F8;color:#000">\'</code> escapes the respective quotation mark
* <code style="background:#F8F8F8;color:#000">\\</code> escapes the backslash
* <code style="background:#F8F8F8;color:#000">\u####</code> (the hash characters stand for four hexadecimal digits) escapes the respective unicode UTF-16 code unit, see [https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals#Unicode_escape_sequences Unicode escape sequences].
*: Note that the database encodes characters in UTF-8 on 1 byte (only characters in the 7-bit US-ASCII characters subset in the range U+0000..U+007F) or more. All ''characters'' that that are assigned a Unicode scalar value in the standard 17 planes are encoded as UTF-8.
*: However, this syntax only supports characters assigned in the BMP (Basic Multilingual Plane), excluding ''surrogates'' which are not Unicode ''characters'' and have no valid UTF-8 encoding (even if code points assigned to ''surrogates'' have a 16-bit scalar value). Non-ASCII characters in the BMP are encoded with UTF-8 on 2 bytes (in the range U+0080..U+07FF), or 3 bytes (in the range U+0800..U+FFFF, minus ''surrogates'' in the range U+D800..U+DFFF).
*: Unicode characters outside the BMP can be represented in UTF-16 as a pair of surrogates: only ''valid'' pairs of UTF-16 surrogates (a ''high surrogate'' in U+D800..U+DBFF immediately followed by a ''low surrogate'' in U+DC00..U+DFFF) are convertible to UTF-8 in the database, and can be escaped as <code style="background:#F8F8F8;color:#000">\uD###\uD###</code> (the result of escaping invalid pairs of surrogates or unpaired surrogates is undefined); these valid escaped pairs of surrogates will be internally converted to UTF-8-encoded sequences of 4 bytes (in supplementary planes 1 to 16); characters in the last valid supplementary planes 15 and 16, assigned only for ''private use'', are supported but not useful in OSM data as they are not interoperable.

In general, there is currently '''no support''' for the common escaping syntax <code style="background:#FEE;color:#F00">\U000#####</code> used in modern C to represent a codepoint in any one of the 17 valid Unicode planes (excluding surrogates), and not even for arbitrary 8-bit bytes with the common escaping syntax <code style="background:#FEE;color:#F00">\x##</code> (defined in C independently of the encoding used). As much as possible escaping should be avoided if it's not needed, and valid UTF-8 used directly in requests.

=== File extension ===

When an Overpass QL query should be saved to a file, please use the <code>.overpassql</code> file extension. This way, the syntax of the file is immediately clear and unique to Overpass QL, making it easy to search for documentation. Also, syntax highlighting engines can rely on a unique file extension, too.

Note that other currently popular file extensions like <code>.ql</code>, <code>.oql</code>, <code>.osm</code>, <code>.query</code> or even <code>.txt</code> are not unique to Overpass QL, and thus syntax highlighting and/or other people might be confused about the file format.

== Misc features ==

=== Map way/relation to area (''map_to_area'') ===

The ''map_to_area'' statement maps OSM object ids for relations to their Overpass API area id counterpart.
Closed ways are passed from the input set to the output set.
Thus you can use the output as a complete list of relevant areas.

This is done by applying the following mapping rules inside Overpass API:

* For relations: add 3600000000 to the relations's OSM id.

Example:
<syntaxhighlight lang="cpp">
rel(62716);
out; // output relation 62716
map_to_area; // map OSM relation to Overpass API area by adding 3600000000 to its id
out; // output area 3600062716
</syntaxhighlight>

The main use case of this statement is to search for objects inside an area, which is again inside another area ("area in area query").

'''Notes''':
* The Overpass API internal area creation job does not create an area for each and every relation in OSM. If an area does not exist for a given relation, map_to_area will simply skip this object without adding an area. Otherwise the area will be returned but with its geometry as it was when it was last created or updated by an internal background process on the Overpass server, and it may be different from the most recent geometry loaded from the relation element in the OSM database.
* Using areas in queries instead of actual OSM elements may speed up the Overpass queries as these geometries don't need to be fully loaded from possibly many child elements from the OSM database, and then converted by connecting ways with common nodes.
* Also not all relations and ways may convert to a valid area (even if their tags normally imply that they should be valid areas) if they don't create properly closed ''rings''.
*see also: [[Overpass API/Areas]]

The following examples outline some possible use cases for this statement:

<u>Example 1: Find all pubs in the inner city of Cologne</u>

Querying only for an area named "Innenstadt" would return quite a number of areas, not limited to Cologne.

{{OverpassTurboExample|query=
area[name="Köln"]->.b;
rel(area.b)[name="Innenstadt"];
map_to_area -> .a;
node(area.a)[amenity=pub];
out meta;
}}

<u>Example 2: Find all municipalities (admin_level=8 !) in ''Hessen'' without fire station</u>

{{OverpassTurboExample|query=
area[admin_level=4]["name"="Hessen"][boundary=administrative]->.boundaryarea;
( node(area.boundaryarea)["amenity"="fire_station"];
way(area.boundaryarea)["amenity"="fire_station"];
>;
) ->.a;

.a is_in -> .b;
area.b[admin_level=8] -> .bf;

rel(area.boundaryarea)[admin_level=8];
map_to_area -> .bllf;

(.bllf; - .bf; );
rel(pivot);
(._;>;);
out;
}}

<u>Example 3ː Count the number of pharmacies per county</u>

{{OverpassTurboExample|query=
[out:csv(::"type",::"id", name, admin_level,::"count")];
area[name="Saarland"][boundary];
rel(area)[boundary][admin_level=6];
map_to_area;
foreach->.d(
(.d;);out;
(node(area.d)[amenity=pharmacy];
way(area.d)[amenity=pharmacy];
relation(area.d)[amenity=pharmacy];);
out count;
);
}}

<u>Example 4ː Named input set</u>

{{OverpassTurboExample|query=
rel(62716)->.b;
.b out;
.b map_to_area;
out;
}}

<u>Example 5ː Find the number of bicycle parking facilities per county in California</u>

{{OverpassTurboExample|query=
[out:csv(::"type",::"id", name, admin_level,::"count")];
area[name="California"][boundary];
rel(area)[boundary][admin_level=6];
map_to_area;
foreach->.d(
(.d;);out;
(node(area.d)[amenity=bicycle_parking];
way(area.d)[amenity=bicycle_parking];
relation(area.d)[amenity=bicycle_parking];);
out count;
);
}}

<u>Example 6ː Find all primary roads in London not part of a bus route</u>

{{OverpassTurboExample|query=
area[name="London"]->.a;
way(area.a)[highway=primary]->.primary_roads;
rel(area.a)[route=bus];
way(r)->.bus_routes;
(.primary_roads; - .bus_routes;);
out body;
>;
out skel qt;
}}

<u>Example 7ː Find Museums in Paris with Nearby Transportation within 50 Meters</u>

{{OverpassTurboExample|query=
area[name="Paris"]->.a;
(
node(area.a)["tourism"="museum"];
way(area.a)["tourism"="museum"];
)->.museums;

(
node(around.museums:50)["highway"="bus_stop"];
way(around.museums:50)["highway"="bus_stop"];
node(around.museums:50)["railway"="tram_stop"];
way(around.museums:50)["railway"="tram_stop"];
node(around.museums:50)["railway"="subway_entrance"];
way(around.museums:50)["railway"="subway_entrance"];
);

/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out meta;

}}

<u>Example 8ː Find cafes that are closer than 20 meters from a pedestrian street</u>

{{OverpassTurboExample|query=
area[name="Berlin"]->.a;
way(area.a)[highway=pedestrian]->.pedestrian_streets;
way(area.a)[amenity=cafe]->.cafes;
way.pedestrian_streets(around.cafes:20);
/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out meta;

}}


<u>Example 9ː Find Natural Reservations that are bigger than 10 km length in Colorado and that do not have a hiking route inside them.</u>

{{OverpassTurboExample|query=
area[admin_level=4]["name"="Colorado"]->.boundaryarea;
( node(area.boundaryarea)["leisure"="nature_reserve"];
way(area.boundaryarea)["leisure"="nature_reserve"];
>;
) ->.a;
.a is_in -> .b;
way.b["route"="hiking"] -> .hiking_routes;
(way(area.boundaryarea)(if: length() > 10000)["leisure"="nature_reserve"]; - .hiking_routes;);
/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out;

}}

<u>Example 10ː Find parks in Berlin that have a playground inside or around 500 meters from the park</u>

{{OverpassTurboExample|query=
area[name="Berlin"]->.region;
rel(area.region)[leisure=park];
map_to_area -> .parks;
node(area.parks)[leisure=playground];
way(area.parks)[leisure=playground];
out;
node(area.parks)[leisure=playground] -> .playgrounds;
node.playgrounds(around:500);
out ;

}}


<u>Example 11ː Find longer than 3 km paved runway in the world</u>

{{OverpassTurboExample|query=
way["aeroway"="runway"]["surface"="paved"](if: length() > 3000);
/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out meta;

}}

<u>Example 12ː Find all bike rental stations in San Francisco within 50 meters of a railway station</u>

{{OverpassTurboExample|query=

area[name="San Francisco"]->.sf;
node(area.sf)["amenity"="bicycle_rental"]->.bike_rental;
node(around.bike_rental:50)["railway"="station"]->.station;
node(around.station:50)["amenity"="bicycle_rental"]->.filtered_bicycle_rental;

(
.filtered_bicycle_rental;
.station;
);
out meta;

}}





== Notes ==
{{References}}

== See also ==

* [https://dev.overpass-api.de/overpass-doc/en/ Overpass API User's Manual]
* [[Overpass API|Overpass API page]]
* [[Overpass API/Language Guide|Overpass Language Guide]]
<!-- * [[Overpass API/Overpass_QL|Language Reference]] -->
* [[Overpass API/Overpass API by Example|Examples]]
* [[:Overpass API/FAQ#Query-languages and syntax|FAQ]]
* [[Overpass API/Sparse Editing|Sparse Editing]]
* [[SPARQL vs Overpass QL examples|SPARQL vs. Overpass QL examples]]
* Tutorial to learn Overpass with hands on - https://osmlab.github.io/learnoverpass/en/

[[Category:Overpass API|Overpass QL]]
[[Category:Technical guide]]
[[Category:Translate to German]]