This is a static archive of our old OSM Help Site. Please post any new questions and answers at community.openstreetmap.org.

overpass: stats per value

0

I'd like to generate some statistics about the members of a relation. This is as far as I've gotten:

[out:csv(number,length)][timeout:25];
(
  relation(id:3121667)->.groute;
);
way(r.groute);
make stat number=count(ways),length=sum(length());
out;

Now, I would like to have a row in the CSV for every unique combination of highway and surface. So for example the total length of secondary - asphalt roads in this relation. I looked at the API doc and the examples, but I really don't see how

asked 15 Dec '20, 12:32

joost%20schouppe's gravatar image

joost schouppe
3.4k245087
accept rate: 12%


One Answer:

2
[out:csv(highway,surface,number,length)][timeout:25];
relation(id:3121667)->.groute;
way(r.groute);

for->.hw (t["highway"]) {
  for.hw (t["surface"]) {
    make stat highway=hw.val, surface=_.val, number=count(ways), length=sum(length());
    out;
  }
}

This was a great help to figure out for loops and how to access the tags we're grouping by (hw.val and _.val): https://dev.overpass-api.de/blog/loop_and_group.html

answered 15 Dec '20, 13:24

M1dgard's gravatar image

M1dgard
15635
accept rate: 16%