Overpass query example

Search inside a city by name

Use area["name"=…] to search inside the real boundary of a city instead of a rectangle. Example: every bakery in Vienna.

A bounding box is a rough rectangle. To search inside a real boundary such as a city, a region or a country, turn the boundary into an area and search in it.

This query finds every bakery in Vienna.

The query

[out:json][timeout:60];
area["name"="Wien"]["admin_level"="4"]->.city;
nwr["shop"="bakery"](area.city);
out center;

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. area["name"="Wien"] finds the area made from the boundary of Vienna. Names are matched exactly and in the local language.
  2. ["admin_level"="4"] picks the right boundary. Many places share a name, and Vienna is both a city and a federal state (level 4).
  3. ->.city stores the area in a set named city.
  4. nwr["shop"="bakery"](area.city) finds nodes, ways and relations tagged shop=bakery inside it.
  5. out center; gives one coordinate per result, also for buildings.

Variations

  • Not sure about the admin_level? Use which areas contain a point to list the boundaries at a place.
  • To be unambiguous, match the Wikidata ID instead of the name: area["wikidata"="Q1741"]->.city;.
  • For a whole country, use its ISO code: area["ISO3166-1"="AT"][admin_level=2].

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 →