Overpass query example

Your first query: cafés in a bounding box

The simplest useful Overpass query: every café inside a rectangle of latitudes and longitudes, with a line-by-line explanation.

Every Overpass query answers one question: which map elements match these conditions? The simplest condition is a bounding box, a rectangle given by its south-west and north-east corners.

This query finds all cafés mapped as points in central Zürich.

The query

[out:json][timeout:25];
node["amenity"="cafe"](47.365,8.535,47.380,8.555);
out;

Run it

Running the query…

Live result from overpass.ch, cached for up to 12 hours. Map data © OpenStreetMap contributors (ODbL).

How it works

  1. [out:json][timeout:25]; is the settings line: answer in JSON and give up after 25 seconds.
  2. node searches points. Ways (lines and outlines) and relations are separate element types.
  3. ["amenity"="cafe"] keeps only elements with the tag amenity=cafe.
  4. (47.365,8.535,47.380,8.555) is the bounding box in the order south, west, north, east.
  5. out; prints what was found, with coordinates and tags.

Variations

  • Many cafés are mapped as building outlines, not points. Use nwr instead of node and out center; to get them too: see nodes, ways and relations at once.
  • The {{bbox}} shortcut only works inside Overpass Turbo. In your own code, write the four numbers.

Run it from your code

curl https://api.overpass.ch/v1/YOUR_API_KEY/interpreter \
  --data-urlencode 'data@query.overpassql'

Save the query as query.overpassql. It works the same in Overpass Turbo, QGIS and JOSM.

More examples

All examples →