Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: add function to sum up spatial length of ways #237

Closed
saerdnaer opened this issue Oct 12, 2015 · 4 comments
Closed

Idea: add function to sum up spatial length of ways #237

saerdnaer opened this issue Oct 12, 2015 · 4 comments

Comments

@saerdnaer
Copy link

like the experimental count function but not the number of elements but the spatial length of non-closed ways.

@drolbr
Copy link
Owner

drolbr commented May 25, 2017

Implemented in 0762e15

Syntax is: length() as evaulator. An example:

way[name="Wilhelm-Stricker-Weg"];
out geom;
make stats length=sum(length()),section_lengths=set(length());
out;

@tordans
Copy link

tordans commented Sep 25, 2021

Update: Have a look at tyrasd/osmtogeojson#130 for my latest workaround.


In case anyone stumbles upon this.

I was wondering how to connect the list of length values from section_lengths to the OSM ways.

Here is my workaround: https://overpass-turbo.eu/s/1buu

[out:json][timeout:25];
(
  way["highway"="service"]({{bbox}});
);
out geom;
make stat total_length=sum(length()),way_id_length=set(type() + ",#" + id() + ",length(m):" + length());
out;

Which returns a string that can be processed to get the length per way-id.

{
  "type": "stat",
  "id": 1,
  "tags": {
    "total_length": "58.626",
    "way_id_length": "way,#262073667,length(m):18.509;way,#262073675,length(m):40.117"
  }
}

Another way would be to trust in the fact(?) that the order of all values of make-variable(ids, lengths) is the same, so make test ids=set(id()),lengths=set(length()); could be used to split (by ;) and match by array index.

{
"type": "test",
"id": 1,
"tags": {
 "ids": "262073667;262073675",
 "section_lengths": "18.509;40.117"
}
}

Other thinks I learned:

  • It looks like there is no way to add (merge) the length output to the elements-object of type:way; it is always separate from the OSM elements. Update: See Rolands reply below
  • stats can be any string, its just the value for the "type": "stats".
  • The variable names can have any value (length=sum(length()) could be total_length=…).
  • One can access tags-values with t["highway"], but the result will be compacted.
  • The way make is used above, one can only have on make-call.

@drolbr
Copy link
Owner

drolbr commented Sep 26, 2021

General remark: please do not comment on issues that are closed since years. Most likely, nobody will ever read that. Rather feel free to open a new issue for a remark.

For the given problem I suggest

[out:json];
way["highway"="service"]({{bbox}});
convert result ::=::,::geom=geom(),length=length();
out geom;

The convert statement amends each OSM element with a length tag. The result can be seen on this Overpass Turbo instance. The main instance does not support the produced GeoJson.

@DaveF63
Copy link

DaveF63 commented Jul 23, 2022

please do not comment on issues that are closed since years. Most likely, nobody will ever read that.

I disagree with this. Given software is updated, an original, accepted answer can often be wrong. Many come to these pages via a google search.

I came to this page via the 'Related Questions' column on the OSM help forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants