NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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%


[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

permanent link

answered 15 Dec '20, 13:24

M1dgard's gravatar image

M1dgard
15635
accept rate: 16%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×228
×5

question asked: 15 Dec '20, 12:32

question was seen: 1,103 times

last updated: 15 Dec '20, 13:24

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum