Skip to content

Instantly share code, notes, and snippets.

@njanakiev
Last active July 30, 2023 19:24
Show Gist options
  • Save njanakiev/bb63108976815887545c0e9e6527b83c to your computer and use it in GitHub Desktop.
Save njanakiev/bb63108976815887545c0e9e6527b83c to your computer and use it in GitHub Desktop.
Overpass API Recipes

Overpass API Recipes

Get all the peaks in the dolomites

area
  [place=region]
  ["region:type"="mountain_area"]
  ["name:en"="Dolomites"];
out body;

// get all peaks in the area
node
  [natural=peak]
  (area);
out;

Get the center coordinate of all Biergarten in Germany

area["ISO3166-1"="DE"][admin_level=2];
( node["amenity"="biergarten"](area);
  way["amenity"="biergarten"](area);
  rel["amenity"="biergarten"](area);
);
out center;

Get center coordinate of all marked bitcoin ATMs

( node["amenity"="atm"]["currency:XBT"="yes"];
  node["amenity"="atm"]["brand"="Bitcoin"];
  node["amenity"="atm"]["name"="Bitcoin"];
);
out center;

Get the boundary of a country

rel[admin_level=2]["ISO3166-1"="DE"];
out geom;

To get the administrative boundary of a given country for other admin_level use rel[admin_level=3]["is_in:country"="XX"]; and rel[admin_level=4]["ISO3166-2"~"^XX"]. Details on the admin_level tag can be found in the Key:boundary documentation.

Get all postal boundaries of Leipzig

area(3600062649);
rel(area)["boundary"="postal_code"];
out geom;

The area id can be calculated from an existing OSM way by adding 2400000000 to its OSM id, or in case of a relation by adding 3600000000 respectively. Note that not all ways/relations ave an area counterpart (tagged with area=no, and most multipolygons and that don't have a defined name=* will not be part of areas).

Get all the capitals in the world

node[capital=yes]; out;

Get the boundary of a city

You can achieve this by either using an Area pivot

area[name="London"][admin_level=6][boundary=administrative]->.londonarea;
rel(pivot.londonarea);
out geom;

or by directly accessing the relation

rel[name="London"][admin_level=6][boundary=administrative];
out geom;

Get the bounding box of Dublin

rel[name=Dublin][place=city][admin_level=7]; out bb;

Get all restaurants within 1 km radius around the Eiffel Tower

way[name="Tour Eiffel"];
(node[amenity=restaurant](around:1000.0);
 way[amenity=restaurant](around:1000.0);
 rel[amenity=restaurant](around:1000.0);
);
out;

where the format of around is (around[.input_set]:radius) or (around:radius,latitude,longitude).

Fetch parents of an input set

( node(3815147164); <; );
out geom;

where < is recursive up and for relations you need to use <<.

Get all results within a boundary and all connected elements

E.g. get all lanes in and from the City of London.

area[name="City of London"][type=boundary][boundary=administrative];
way["name"~"Lane"](area);
<;>;
out geom;

Load OSM Data with curl

curl --globoff -o data.json http://overpass-api.de/api/interpreter?data=[out:json];node(1);out;

Note that the query after ?data= has to be urlencoded and the --globoff flag needs to be added not to interpret []{} inside the url.

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment