Is there a way to select a relation with all of its members belonging to a specific area?

I'm currently working with hiking routes and I want to store all the hiking tracks for a given input area. As far as I understand from the docs, even if a relation has only one member in the selected area it will be included. Is there any simple workaround to avoid that?

Here is a basic example, any suggestion would be much appreciated. I'm quite new to OSM and OverpassQL, sorry in advance if this is elementary stuff.

asked 01 Jun, 01:13

Debo790's gravatar image

Debo790
103
accept rate: 0%

Just to make sure we understand each other: You want to extract all relations of which all members are inside a certain area. If any member is outside that area you want to exclude the whole relation. Is that the correct understanding?

(01 Jun, 08:10) TZorn

Yes, correct. In the example provided the difference is minimal, but considering a larger area (e.g. a region, or a province) you may end up including routes that cover all the nation. This is an issue for me at the moment and I didn't find anything useful in other questions.

(01 Jun, 08:59) Debo790

One approach is to use around:0 to detect where routes cross the members of the query area. Proof of concept: http://overpass-turbo.eu/s/1812

I didn't look at the output to see if it was entirely correct, but it at least goes in the right direction. I'm not sure if it would work to use the relation as one of the inputs (using the member ways ensures that only intersections with the boundary are considered; it may work the same with the relation as the input).

permanent link

answered 01 Jun, 22:57

maxerickson's gravatar image

maxerickson
12.5k1079175
accept rate: 31%

This seems to work fine, it becomes quite heavy scaling the boundaries up to provinces but keeping admin_level=8 results are good even in terms of time. I've perfomed some tests with cities full of hiking routes and also with cities that shows no routes at all, results seems correct in both cases. Thanks a lot!

(02 Jun, 01:09) Debo790
area[name=Spoleto][admin_level=8]->.Spoleto; //Search Area
rel(pivot.Spoleto)->.Bound; //convert to way to render
.Bound out geom;
(
rel[route=hiking](area.Spoleto)->.Within; // All hikes within search area
-  
rel .Within(around.Bound:0); //Remove those which cross boundary
);  
out geom;
permanent link

answered 04 Jun, 21:32

DaveF's gravatar image

DaveF
2.1k6376101
accept rate: 10%

This now retrieves the correct results, but it doesn't check for multiple cities (e.g. Milano or Roma). The code provided in the question (and in answer of maxerickson) deals with it using this: https://help.openstreetmap.org/questions/64305/overpass-api-get-city-boundaries-within-a-country-slow-query/70342

Obviously this decreases performances, but it's the best I came up with so far. Thanks for your effort anyway, your solution is the way to go when dealing with cities with no homonyms.

(05 Jun, 09:15) Debo790

The nearest I've ever been able to trim to a boundary is to Recurse down to the way members & then search within the area, but this includes ways which overlap the boundary.

area[name=Spoleto][admin_level=8]->.Spoleto;
rel[route=hiking](area.Spoleto);
way(r)(area.Spoleto);
out geom;
rel(pivot.Spoleto);
out geom;

PS I wish OP had a global area option similar to bbox. It would save a lot of typing.

permanent link

answered 03 Jun, 16:56

DaveF's gravatar image

DaveF
2.1k6376101
accept rate: 10%

This is actually faster, but it includes ways relations that shouldn't appear. An example is in the comment above the query: http://overpass-turbo.eu/s/185E The aim is to find relations with all the members inside the given area, if some of those members are outside then the whole relation should be discarded.

(04 Jun, 00:18) Debo790
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:

×424
×209
×191
×120

question asked: 01 Jun, 01:13

question was seen: 180 times

last updated: 05 Jun, 09:15

powered by OSQA