Overpass query example

Count values of a tag

Group and count with a for loop and make: how many restaurants of each cuisine. Example: Zürich.

for groups the current set by an expression, and make creates a new element for each group. Together they work like GROUP BY in SQL.

The query

[out:csv(name, total; true; ",")][timeout:60];
area["name"="Zürich"]["admin_level"="8"]->.a;
nwr["amenity"="restaurant"](area.a);
for (t["cuisine"]) {
  make stat name=_.val, total=count(nwr);
  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. for (t["cuisine"]) loops over the distinct cuisine values; _.val is the current value.
  2. Inside the loop, the set holds only the restaurants with that value. count(nwr) counts them.
  3. make stat … creates a row; with CSV output each row is one line. The empty name counts restaurants without cuisine.

Variations

  • Sort the CSV in your spreadsheet, or by value with sort -t, -k2 -n.

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 →