How to determine allowed directions of travel for an edge?

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.

Those properties are relative to the base node and should indeed give you this information, of course you need to use a car or bike not e.g. a foot encoder. Is this not working for you?

Thank you for such a quick reply!

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, “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?

Currently that is the API, yes. But do not use a new CarFlagEncoder instance, instead use the one you passed to the EncodingManager, or fetch it from there: encodingManager.getEncoder(“car”)

BTW: we try to improve the usage of this in this issue:

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.

Using the same encoder instance did the trick. Thank you! :slight_smile:

1 Like

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());

Thank you so much. This is a massive help, i was beginning to think i would have to give up and do this all by hand!