This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How to make area from specific node or relation, using it’s element id number in Overpass QL?

0

I can make an area in Overpass QL, using name and relation attributes (tags) filter of element, something like this:

area["name:en"="Moscow Oblast"]["boundary"="administrative"]["admin_level"="4"]->.region;
(node(area.region)[place="city"];node(area.region)[place="town"];);
out;

But searching via name is not so stable, and will broke if element name is changed. So much better (for performance too) is to make an area from element id. Here is example of searching relation via it's element id:

rel(51490);
out;

And can't understand, how to pass element type and id to area query? Something like this:

area(rel(51490))->.region;
(node(area.region)[place="city"];node(area.region)[place="town"];);
out;

or other variants like area["id"=51490]->.region; or area["type"="rel"]["rel"=51490])->.region; don't works.

Can anyone give me an example, how to make area from OSM element by it's id?

asked 09 Nov '20, 09:34

Murz's gravatar image

Murz
11112
accept rate: 0%


2 Answers:

2

From the wiki:

By convention the area id can be calculated from an existing OSM way by adding 2400000000 to its OSM id, or in case of a relation by adding 3600000000 respectively.

https://overpass-turbo.eu/s/ZTF

area(3600051490);
node(area)[place~"^(city|town)$"];
out;

Multiple areas can be combined (note the 'id:'):

area(id:3600058447,3600058437,3600058446); // England, Wales, Scotland

answered 09 Nov '20, 12:38

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

edited 13 Nov '20, 19:32

Thanks for solution! It is very interesting trick with id's, that I don't know before.

(09 Nov '20, 12:42) Murz

0

Other solution, provided from @mmd, is to use result of fist search via id of element as area, example:

rel(51490);map_to_area->.region;
node(area.region)[place="city"];
out;

answered 09 Nov '20, 12:43

Murz's gravatar image

Murz
11112
accept rate: 0%

edited 09 Nov '20, 12:43

That's basically the same but with a conversion: https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Map_way.2Frelation_to_area_.28map_to_area.29


btw where did @mmd post the reply?

(09 Nov '20, 13:01) DaveF

In Slack, because I ask similar question in Slack too, but before creating question here.

(09 Nov '20, 13:19) Murz

Source code available on GitHub .