6

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); way(bn); out;

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?

  • 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 '17 at 21:15
  • 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. – Erwin Poeze Jun 16 '17 at 12:49
6

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:

{"annotation":{"nodes":[659394041,3836987625,3275541361,26871569,3836987634,3836987635,3836987636,588159289,311718989,3836987640,...,3030636206],"datasources"

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:

node(id:659394041,3836987625,3275541361,26871569,3836987634,3836987635,3836987636,...,2164561317,3324300228,3030636206);
way[highway](bn);
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:

node(id:659394041,3836987625)->.allnodes;

way[highway](bn.allnodes)->.ways;

foreach .ways -> .singleway (
   node.allnodes(w.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 – Erwin Poeze Jun 17 '17 at 6:55
  • @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 '17 at 8:51

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.