I have a route geometry in the format:

  • OSM node-1 coordinates
  • OSM node-2 coordinates
  • OSM node-3 coordinates
  • ...

And I need to know which OSM ways were "used" by the route.


Is there an Overpass query which can return me the ways which are required to "form" the route geometry with one request?

  • fyi: The geometries' route is always "connected" by shared way nodes.


  • input: geometry = [node102, node103, node104, node303, node304]
  • output: wayIds = [way1, way2, way3]
  • where way1 is e.g. [node101, node102, node103, node104, node105]
  • where way2 is e.g. [node104, node303]
  • where way3 is e.g. [node303, node304, node305]


I'm using a routing API which only returns the Geometry of the Route (OSM node coordinates) but no ids.

The problem is that I need to know which OSM ways were used to construct this route.

What I've tried so far

  1. I can get all the node id from the node coordinates using node(around:0,lat,lon)

  2. Thanks to this I can get the ways which contain a set of nodes using



foreach .ways -> .singleway (
  way.singleway(bn)(if:count(nodes) == allnodes.count(nodes));
  out geom;
  1. Unfortunately I don't know how many nodes of a way were used by the route. Right now I only can think of:

    a. find all ways for node1, node2

    b. if more than one way found --> add another node to (a) and try again

    c. when I found the way, search the next way with the geometries next node pair which is not part of the way I just found (i.e. continue with (a))

    But this approach would require me to make many request to the Overpass API. I can't figure out how to write this logic as Overpass Query. I'm running my own overpass server.

1 Answer 1


The solution I picked was:

  • map-match the route (again) with Valhalla Map-Matching mode trace_attributes and algorithm shape_match:edge_walk

  • The edge_walk algorithm takes into account that the input route was already matched close to the OSM ways.

  • This mode returns the way ids used by the matched route.

  • With these wayIds I can query Overpass with one simple, fast query to get all the other way data for all ways: way(id:1, 2, 3, 4, ...)

Your Answer

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

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