Overpass query example

Municipalities of a region

Get all municipal boundaries inside a region. Example: the canton of Zug.

Search boundaries inside another boundary: here all municipalities (admin_level 8) inside a Swiss canton. Regions are selected by their ISO 3166-2 code.

The query

[out:json][timeout:25];
area["ISO3166-2"="CH-ZG"]->.zug;
rel["boundary"="administrative"]["admin_level"="8"](area.zug);
out geom;

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["ISO3166-2"="CH-ZG"] is the canton of Zug. Regions in every country have such codes.
  2. A relation is “in” the area when part of it is, so neighbouring municipalities that touch the border may appear. Filter them with (if: …) or check is_in if needed.

Variations

  • Districts or counties instead: change the admin_level (the levels differ by country).

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 →