I'm trying the retrieve the "WAY", that passes two given "INTERSECTIONS".

What I do is query for the NODE, that intersects the INTERSECTION using the locations of this intersections (which is returned by OSRM). I use the locations as a bounding box in Overpass:

nodes(north, west, south, east);

The result is there, but all ways attached to the two nodes are returned. How do I filter so only the WAY that passes both NODEs is returned?

  • 1
    I'm not sure that approach really works. According to the OSM data model, there's absolutely no guarantee that there's a single way which includes those two intersection nodes. It could actually be split several times and your Overpass query would never return anything usefull. OSRM merges the data to make them look like one way, but the actual OSM data representation is a completely different story. Can you elaborate in more detail what exactly you're trying to do from a functional point of view, and why you want to use Overpass API for that purpose?
    – mmd
    Jun 15, 2017 at 21:15
  • 1
    What I try to do is to map a gps position to the nearest road (using the current and x previous positions) and retrieve the properties of this road. Jun 16, 2017 at 12:49

1 Answer 1


The following description assumes that you have a list of GPS positions, as well as the OSRM map matching service and Overpass API available.

(1) Use OSRM Map Matching service to identify nearest roads for a trip

OSRM Map matching service accepts a list of GPS positions, or some polyline and matches it to the corresponding OSM ways. This will be the first step of the overall process and returns a list of OSM nodes ids for further processing.

Example: http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?annotations=nodes

I used parameter annotation=nodes to include all OSM node ids in the result:


See https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#match-service for details.

(2) Fetch ways for node ids via Overpass API

Based on the previous result, extract all OSM node ids and pass those node ids to Overpass API. The following query then retrieves all corresponding highways for those node ids:

out geom;

Overpass turbo link: http://overpass-turbo.eu/s/pOT

Same query including OSM nodes from both legs in OSRM response: http://overpass-turbo.eu/s/pOW - that's actually a trip from Friedrichstraße via Torstraße to Platz der Vereinten Nationen in Berlin, Germany.

Ways according to a list of node ids

To find a way which contains all of a given list of node ids, you can use the following approach:



foreach .ways -> .singleway (
   way.singleway(bn)(if:count(nodes) == allnodes.count(nodes));
   out geom;

overpass turbo link: http://overpass-turbo.eu/s/pPq

  • Thanks @mmd, this works indeed if you want all ways attached to a set of node. But what if you only want way(s) that pass two specific nodes? I reduced you example to two nodes: overpass-turbo.eu/s/pPg and I would like to have returned the way with id 36689634 only (the only way that included both nodes Jun 17, 2017 at 6:55
  • 1
    @ErwinPoeze: I added this as another option now, although you might easily run into rate limiting by using this approach. If this answers your question, kindly ask to accept it. Thanks.
    – mmd
    Jun 17, 2017 at 8:51

Your Answer

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

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