When querying data from the LocationIndex, is it possible to determine the allowed directions of travel for the returned EdgeIteratorState? I’m trying to run a getClosestEdge() query and find whether or not the road is one-way, and if so what direction it is in.
I’ve tried looking at the isForward and isBackward properties, but from ohter questions here it seems that is to do with how the query is iterating over the graph.
I am currently inspecting the forward and backward properties the manner edge.isForward(new CarFlagEncoder()) - is this right? I have tried on both one-way and two-way roads and in each case the result always seems to be false for both. I have CH disabled.
Also, the EdgeIteratorState returned from my queries always seems to have the base and adjacent node in the opposite direction to the allowed direction of travel. This matches up with what you said at https://lists.openstreetmap.org/pipermail/graphhopper/2013-October/000492.html, “the edge iterator does not necessarily reflect the direction of a street”. So even if I can get the forward and backward properties working OK, surely this means I don’t know the “real” direction of travel?
the EdgeIteratorState returned from my queries always seems to have the base and adjacent node in the opposite direction to the allowed direction of travel
The adjacent and base are relative to the exploration in the graph. Assume the one-way 1->2 then if base node = 1 and adj node = 2 then forward is true and backward is false, but if base=2 and adj=1 then forward is false and backward is true.
Hi I have exactly the same question as the original post - from a getClosestEdge() query how do i determine if the edge is one way in the underlying OSM data and what that direction is. If i call fetchWayGeometry it sometimes returns the points in the right order and other times not. Really struggling to find any good documentation on this. Any help would be greatly appreciated.
Information about which roads are one-ways is stored using access flags for each edge. This depends on the vehicle/encoder. To find out if an edge is a one way you therefore need to use the access encoded value:
EdgeIteratorState edge = queryResult.getClosestEdge();
int nodeA = edge.getBaseNode();
int nodeB = edge.getAdjNode();
boolean edgeCanBeTraveledFromAToB = edge.get(flagEncoder.getAccessEnc());
boolean edgeCanBeTraveledFromBToA = edge.getReverse(flagEncoder.getAccessEnc());
Why is p2 routed onto the same edge but in the reverse direction?
Maybe the snapping to the edge is not fully deterministic? If this is the case we should of course fix this. This is especially surprising because you said it is a one-way edge.
When reverse=true, does this imply that the way geometry of the edge and all its internal flags are reversed relative to the travel direction?
Yes, at least for those edge properties that differ between the two directions. For example the speed can be different for the two directions and the way geometry will be reversed, but encoded values like ‘surface’ are usually the same for both directions.