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
Live result from overpass.ch, cached for up to 12 hours. Map data © OpenStreetMap contributors (ODbL).
How it works
area["name"="Wien"]finds the area made from the boundary of Vienna. Names are matched exactly and in the local language.["admin_level"="4"]picks the right boundary. Many places share a name, and Vienna is both a city and a federal state (level 4).->.citystores the area in a set namedcity.nwr["shop"="bakery"](area.city)finds nodes, ways and relations tagged shop=bakery inside it.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'
import requests
query = open("query.overpassql").read()
r = requests.post("https://api.overpass.ch/v1/YOUR_API_KEY/interpreter",
data={"data": query}, timeout=120)
r.raise_for_status()
print(r.json()["elements"][:3])
const res = await fetch("https://api.overpass.ch/v1/YOUR_API_KEY/interpreter", {
method: "POST",
body: new URLSearchParams({ data: query }),
});
if (!res.ok) throw new Error(await res.text());
console.log(await res.json());
Save the query as query.overpassql. It works the same in Overpass Turbo, QGIS and JOSM.