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

[Overpass-api] How to get all relations for a node/way?

3
1

Speaking in Overpass QL I can select a node by its ID:

node(3815147164);out;

This however doesn't provide any info about relations or ways this node is a part of.

Going to OSM site: https://www.openstreetmap.org/node/3815147164 I can see at least which ways the node belongs to. And then to the way page: https://www.openstreetmap.org/way/136322077 I see its relations.

In Overpass relations are not returned, even for the way query:

way(136322077);out;

Any ideas how to get relations?

asked 29 Jan '16, 07:44

ivanatora's gravatar image

ivanatora
2.7k355568
accept rate: 7%

edited 29 Jan '16, 10:17


2 Answers:

3

Overpass API only returns objects that are explicitly included in the query. To fetch the parents of an input set, use recurse up:

(node(3815147164);
<;
);
out geom;

Note that < does not fetch the parents of relations, use << for that.

There are also some more fine grained operators if you only want the parent ways of nodes or whatever:

https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Recurse_.28n.2C_w.2C_r.2C_bn.2C_bw.2C_br.29

answered 29 Jan '16, 14:59

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

2

Node 3815147164 is not part of any relation itself. It is part of way 136322077 which in turn is part of a relation. You already seem to have figured this out by yourself but your question is still a little bit misleading.

You don't need Overpass API for returning the ways a node is part of, see https://www.openstreetmap.org/api/0.6/node/3815147164/ways. And you don't need Overpass API for returning the relation a node or way is part of, see https://www.openstreetmap.org/api/0.6/way/136322077/relations.

If this doesn't really answer your question then maybe someone can come up with an Overpass API query for returning the relation(s) containing way(s) a node is part of.

answered 29 Jan '16, 09:22

scai's gravatar image

scai ♦
33.3k21309459
accept rate: 23%

edited 29 Jan '16, 09:23

Yeah, you are right. I've changed the title a bit, to match my intention in a better way.

I'd like to have a pure Overpass solution and not having to mix different APIs in the same application.

(29 Jan '16, 10:19) ivanatora

Source code available on GitHub .