Overpass query example

Total length of cycleways

Compute a sum over geometries with make and length(). Example: kilometres of cycleways in Bern.

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

Running the query…

Live result from overpass.ch, cached for up to 12 hours. Map data © OpenStreetMap contributors (ODbL).

How it works

  1. Another place called Bern also has admin_level 8. ["wikidata"="Q70"] picks the Swiss capital.
  2. length() is the length of each way in metres.
  3. sum(…)/1000 adds them up and converts to kilometres.
  4. make stat returns one element with the result as its km tag.

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'

Save the query as query.overpassql. It works the same in Overpass Turbo, QGIS and JOSM.

More examples

All examples →