Overpass keeps the old versions of every element. With the [date:…] setting, the whole query runs on the data of that moment: the tags and positions elements had then, and the elements that existed then.
This query finds the cafés in central Zürich on 1 January 2015. The first example searches the same box today.
The query
[out:json][timeout:60][date:"2015-01-01T00:00:00Z"]; nw(47.365,8.535,47.380,8.555)(if:t["amenity"]=="cafe"); out center;
Run it
Live result from overpass.ch, cached for up to 12 hours. Map data © OpenStreetMap contributors (ODbL).
How it works
[date:"2015-01-01T00:00:00Z"]sets the moment, in UTC. Every statement of the query sees the data of that moment.nw(47.365,8.535,47.380,8.555)searches nodes and ways in the box. Relations are left out: at a past date they make a query many times slower.(if:t["amenity"]=="cafe")keeps the cafés. In history queries this is faster than["amenity"="cafe"], because the tag is checked only on the elements in the box.out center;prints the cafés with the tags and the position they had on that day.- The history starts on 12 September 2012, when OpenStreetMap changed its licence. An earlier date gives only the elements that nobody edited between that date and September 2012.
Variations
- Areas work at a past date, with their current outline:
area["name"="Zürich"]["admin_level"="8"]->.a;andnw(area.a). For all of Zürich this takes about 10 seconds. - One object at a past date, for example a shop before it was deleted:
[date:"2024-04-01T00:00:00Z"];node(7815426573);out meta;. - What changed between two dates: see changes in an area.
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.