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

0
1

I am using the following lines to catch a whole river (main stream, side streams and tributaries):

[out:json][timeout:120];
// Set search area
{{geocodeArea:Sweden}}->.a;
// Get river (relation) and its tributaries
// Skip natural=water (used e.g. for islands) and natural=reservoir
(
rel[waterway][name="Luleälven"](area.a); 
wr[waterway][destination="Luleälven"][!natural](area.a);
) -> .river;
.river out geom;

For "simple" rivers that works fine as long as all parts of the river are added to the relation of this river or as long as they have this river stated as destination, e.g. for tributaries.

However, many rivers have larger tributaries that form own relations. For example, the biggest tributary of Luleälven (https://www.openstreetmap.org/relation/6974663) is Lille Luleälven (https://www.openstreetmap.org/relation/12802656). Lilla Luleälven has a couple of tributaries on its own. As long as the relation "Lilla Luleälven" is tagged as "destination=Luleälven" it works fine with the code above.

What does not work is when more levels are added. E.g. if one wants to capture tributaries of the tributary. Ráhpaädno (https://www.openstreetmap.org/way/30833503) which first passes one big lake and one big reservoir before it comes close to yet some other lakes from where one starts calling the river Lilla Luleälven. In this case, the name of the nearest lakes or "Lilla Luleälven" would be a good choice for destination, not "Luleälven" or "Baltic see". (I am sure there are more and better examples.)

Is there any way to select a whole river system in Overpass using the relations that are defined for rivers in a recursive way? For example a command that adds all tributary relations of a river to the main river including the tributaries of the tributaries? That would be great!

All solutions and ideas are welcome, thanks in advance!

asked 20 Aug '21, 14:11

G%C3%A5seborg's gravatar image

Gåseborg
31171016
accept rate: 50%

edited 20 Aug '21, 14:15


There is a convenient solution using the block statment complete and a recourse filter:

[out:json][timeout:120];
// Set search area
{{geocodeArea:Sweden}}->.a;
// Get river (relation) and its tributaries
// Skip natural=water (used e.g. for islands) and natural=reservoir
(
rel[waterway][name="Luleälven"](area.a); 
complete { way(r);node(w);way(bn);rel(bw)[type=waterway]; } 
) -> .river;
.river out geom;

This way, it is not important to tag tributaries with destination, they only need to be connected with the main river (or yet another tributary) at their confluence. A very nice function of Overpass! I am happy :)

What it does (at least as I understand it): Starting with the relation of the main river (Luleälven in this case), way(r) collects all ways that are members of this relation and node(w) collects all nodes that are members of the these ways. Then, way(bn) finds all ways linking to these nodes - these ways are the parts of tributaries closest to the confluence - and, finally, rel(bw) gets all relations linking to the just found ways, i.e. the relations of the tributaries, in our case Lilla Luleälven.

For more information, check:

permanent link

answered 06 Sep '21, 18:11

G%C3%A5seborg's gravatar image

Gåseborg
31171016
accept rate: 50%

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:

×483
×73
×52
×18

question asked: 20 Aug '21, 14:11

question was seen: 924 times

last updated: 06 Sep '21, 18:11

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