Overpass can also calculate. length() measures a way in metres; sum() adds up the whole set.
The query
[out:json][timeout:60]; area["name"="Bern"]["admin_level"="8"]["wikidata"="Q70"]->.a; way["highway"="cycleway"](area.a); make stat km=sum(length())/1000; out;
Run it
Live result from overpass.ch, cached for up to 12 hours. Map data © OpenStreetMap contributors (ODbL).
How it works
- Another place called Bern also has admin_level 8.
["wikidata"="Q70"]picks the Swiss capital. length()is the length of each way in metres.sum(…)/1000adds them up and converts to kilometres.make statreturns one element with the result as itskmtag.
Variations
- This counts separate cycleways only. Lanes on roads are tags on the road: see cycleways and bike lanes.
- Count and length at once:
make stat ways=count(ways), km=sum(length())/1000;.
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.