TransWikia.com

Overpass Query to find ways of a route geometry

Geographic Information Systems Asked on November 1, 2021

Problem

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.

Question

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.

e.g.:

  • 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]

Context

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

node(around:0,latNode1,lonNode1,latNode2,lonNode2)->.allnodes;

way(bn.allnodes)->.ways;

foreach .ways -> .singleway (
  node.allnodes(w.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.

One Answer

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, ...)

Answered by hb0 on November 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP