1

Does the Overpass API provide a way to query a list of nodes and some attributes of their parent ways, and return the data in CSV format?

For example, the following will give me all motorway junctions:

[out:csv(ref, name, ::lat, ::lon)];
// gather results
(
  // query part for: “highway=milestone”
  node["highway"="motorway_junction"]({{bbox}});
);
// print results
out body;
>;
out skel qt;

Is there a way to query the ref=* tag of the roads of which the node is a member?

3

Yes, that's possible:

[out:csv(_ref, name, ::lat, ::lon)];
node["highway"="motorway_junction"]({{bbox}});

foreach {                  // iterate over nodes

  way(bn)[highway~"^(motorway|trunk)$"][ref] -> .ways; // find ways for each node
  if (ways.count(ways) > 0) {                    // check that at least 1 way was found
    convert result                               // assemble result
             ::id   = id(),                      // use node id
             ::geom = center(geom()),            // and node position
             _ref    = ways.u(t["ref"]),         // parent ref tag
             ::     = ::;                        // all remaining tags of the node
    out geom;                                    // print node
  }
}
  • Thanks! I’ve edited the answer to include also trunk roads. There are still issues to be solved where multiple ways with different ref tags are involved: either different spellings (A8 vs. A 8), or the road name actually changes at the junction (A2 becoming S8). The solution to that probably depends on the use case: I would want two rows, one for each road, so it’s probably better to search for the roads and iterate over its junctions. – user149408 Jun 15 at 19:42
  • 1
    To have one single entry for each of the ".ways", you'd need to add another foreach loop and iterate over those ways. – mmd Jun 15 at 19:52
  • So I’ve replaced the if with another foreach, and I get short of 200 results (which looks OK). Problem is, how can I refer to tags of the way from the inner foreach? – user149408 Jun 15 at 20:38
  • 1
    Try this one: overpass-turbo.eu/s/JY8 – mmd Jun 15 at 20:41
  • That did the trick. Thanks again! – user149408 Jun 15 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.