How to Query Roads Within a Relation?

Posted by No Way on 29 June 2022 in English (English).

How does one use the Overpass API Query tool to determine all roads within a given relation?

Comment from Luciano on 30 June 2022 at 00:02

area[name="Ohunkagan"]; way[highway](area); (._;>;); out;

Comment from The_Cute_Chick on 1 July 2022 at 01:25

I was trying to find a way that you could make a given relation the bounding area of a search by just using the relation’s ID but I couldn’t figure it out. But what works to make a given relation be the bounding area is by defining a key-value tag of the relation, as seen in the above example.

Comment from Luciano on 1 July 2022 at 13:06

@TCC I’ve been trying to learn more about the overpass query language (OQL). I think I figured out a reliable way to reference a relation id in an area-based overpass query: e.g. this is the same query above by the city of Ohunkagan’s relation id:

rel(155144); map_to_area -> .a; way[highway](area.a); (._;>;); out;

Comment from The_Cute_Chick on 3 July 2022 at 14:29


Oooh I see. But does it work for finding a key with a given value? For example, all primary highways in Ohunkagan. Again I couldn’t figure the query for it. :

Comment from Luciano on 3 July 2022 at 14:46

@TCC - sure, you can add a key to the second search subquery, e.g.

rel(155144); map_to_area -> .a; way[highway=secondary](area.a); (._;>;); out;

(I use “highway=secondary” because I haven’t yet mapped any primary highways in Ohunkagan - and in fact, running this query to test it, I found a mistake I need to correct!)

Comment from The_Cute_Chick on 3 July 2022 at 17:40


Ah. I happened to search for something that actually didn’t exist and thought my query was incorrect. Oops. 🙃

Login to leave a comment