Overpass API: How to exclude some relation members from a bbox query?

I want to extract all features (nwr) from a given city. I want the ways (w) and all members of multipolygons (r) that intersect the city boundary to be included in the dataset, but not the members of other relations outside the city boundaries.

The following query is a good start, but I can’t figure out how to exclude the members of other relations (except multipolygons) outside the city boundaries. For instance, I get all members of a route relation that goes up to 800 km away from the city!

{{geocodeArea:Sherbrooke}}->.searchArea;
nwr(area.searchArea);
(._;>;); out meta;

Anyone have any ideas?

You could start with:

{{geocodeArea:Sherbrooke}}->.searchArea;
(
nw(area.searchArea);
relation“type”=“multipolygon”;
);
(._;>;); out meta;

This will return all nodes and ways, and al relation with type=multipolygon

As written, the request didn’t work, but with little changes, it got closer from my need. Here is the working version:

{{geocodeArea:Sherbrooke}}->.searchArea;
(
nw(area.searchArea);
relation(area.searchArea)[type=“multipolygon”];
);
(._;>;); out meta;

Thanks

I was writing this on my phone and couldn’t copy it from overpass lol. It was definitely wrong, but great you could get it to work.

1 Like

Based on @DwarfNebula’s answer, I built a three-part query.

/* Step 1 - request all the features within the city limit (city) */
{{geocodeArea:Sherbrooke}} ->.searchArea;
nw(area.searchArea);
( ._; ._<;) ->.city;

/* Step 2 - expend only the relations of interest found in Step 1 (outside_polygons) */
relation.city[type=“multipolygon”][water!=“river”];
(._; ._>;) ->.outside_polygons;

/* Step 3 - Merge both results with an union statement */
(.city; .outside_polygons;) ->.result;
.result out meta;

I also did it with ways, but didn’t find the result relevant for me, that’s why it doesn’t appear in above query.