Search notes:

Overpass API

The Overpass language makes it hard to query OpenStreetMap data that would otherwise be easy to determine with normal SQL. When I tried to learn Overpass, it seemed to me that the language is based on (or even a successor to) Brainfuck, apparently developed under the influence of LSD.
The only nice feature of Overpass is the possibility to query regions (see the area statement and the bbox setting).

Querying an Overpass API endpoint

Python

The following snippet gives an idea how an Overpass API endpoint can be queried with Python:
import requests

query = """
[out:csv(::id,name)];
relation[admin_level="2"];
out;
"""

response = requests.get(
   'http://overpass-api.de/api/interpreter',
    headers = {'Accept-Charset': 'utf-8'},
    params  = {'data'          :  query }
)

response.encoding='utf-8'

with open('overpass-result.csv', 'w', encoding='utf-8') as file:
     file.write(response.text)
There is also the overpy library.

PowerShell

The following snippet gives an idea how an Overpass API endpoint can be queried with PowerShell:
$query = @'

  [out:json];
  nwr [name=Freienstein];
  out;

'@

$res     = invoke-webRequest -method post -body (@{'data' = $query}) https://overpass-api.de/api/interpreter
$resTxt  = $res.Content
$resJson = convertFrom-json $resTxt

foreach($elem in $resJson.elements) {
   "id: $($elem.id) ($($elem.type))"

   if ($elem.type -eq 'node') {
      "  $($elem.lat) $($elem.lon)"
   }

   …
}

curl

curl -s http://overpass-api.de/api/interpreter --data '[out:json]; way(45593112); out;' | jq

Timestamp of data

The overpass database does not have the most actual data. The timestamp of the OSM database is returned in a timestamp_osm_base field:
$ curl -s http://overpass-api.de/api/interpreter --data '[out:json]; way(45593112); out;' | jq -r .osm3s.timestamp_osm_base
2024-05-29T07:10:00Z

Overpass Turbo URL query parameters

The endpoint understands a few URL parameters:
Q=query Run query
q=base64-encoded-query Like Q=, but the query is Base64 encoded.
C= Latitude/longitude and zoom
R Run query (no parameter)
template=predefined-tempate Use a predefined template (key, key-type, key-value, key-value-type or type-id).
w Use wizard

File extension

The proposed file extension for files that store Overpass API queries is *.overpassql.

TODO

Calculating distances

Although there is a length() function, the calculation of distances (notably between two nodes) seems impossible.

Find buildings whose house number is 13

{{geocodeArea:Pfungen}};              // Search in Pfungen

nw                                    // Search nodes and ways
  [building]                          // that have a building and
  ['addr:housenumber']                // an addr:housenumber tag.
  (area)                              // Restrict search to selected area (geocodeArea)
  (if: t['addr:housenumber'] == 13 ); // and keep only those objects whose addr:housenumber value is 13

out geom;

olbricht.nrw/ovt

olbricht.nrw/ovt is a temporary instance of Overpass Turbo (and seems to have an implementation that translates osm to GeoJSON).
The source code is hosted on github (osmtogeojson)

See also

Overpass language constructs such as
Some Overpass API queries
The R package osmplotr creates visually impressive customisable images of OpenStreetMap data downloaded internally via the Overpass API.
Overpass Turbo IDE extensions for the Overpass API
Making Overpass-API requests from a webpage

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745519864, '3.129.17.22', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/OpenStreetMap/API/Overpass/index(168): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78