3

I want to fetch up to around 10 OSM objects and assign them to a set of hand-picked areas (up to around 20 different areas) in a single Overpass query. Is this possible?

So the desired output is:

  1. Node/Way tags and center of first object + area the first object is in
  2. Node/Way tags and center of first object + area the first object is in
  3. ...

I already got this kind of working with wikidata tags:

[out:json][timeout:10];
(
node(id:3959878839);way(id:162817836);
);
foreach->.d(
  (.d;.d >;)->.d; 
  .d out center;
  .d is_in;
  area._[wikidata~"(Q14201325|Q16895860)"];
  out;
);
>;

Overpass Turbo

This returns the node / way data as well as the area the object is in.

Now I realized I cannot identify all areas needed in the future by wikidata tags and want to use the relation IDs.

The relations are:

For area IDs we have to add 3600000000 to the ID.

So I tried

[out:json][timeout:10];
(
node(id:3959878839);way(id:162817836);
);
foreach->.d(
(.d;.d >;)->.d;
.d out center;
.d is_in;
area._area(3611589457);
out;
);
>;

Overpass Turbo

But this does not output the area any more, and I also don't know how to supply the other area IDs here.

1
  • 1
    The documentation you've quoted here is outdated and not the original one (see wiki.openstreetmap.org/wiki/Overpass_API/… ... "For area IDs we have to add 3600000000 to the ID." -> this is no longer recommended: "You should use the map_to_area function to avoid having to make these calculations manually and depend on any hard-coded constants in your query. " Commented Jun 15, 2023 at 20:31

1 Answer 1

2

So I just read the tutorial first. (shame on me I did not do this earlier)

This works:

[out:json][timeout:10];
(
node(id:3959878839);way(id:162817836);
);
foreach->.d(
  .d out center;
  (.d;.d >;)->.d;   
  .d is_in -> .areas;
  ( 
    area(3611589457).areas;
    area(3611589616).areas;  
  );
  out;
);
>;

Also I put the recurse query after printing the features, because I do not need the nodes of the ways in the output.

Overpass Turbo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.