Given an edge ID how do I get its two nodes?

I need all nodes in a certain area. I’m new to Graphhopper and I believe a LocationIndex and its query method is the way to go.
I got all edges (as ints) in an area, but how do I get their nodes?

val hop: GraphHopper = …
val index = hop.getLocationIndex()
val visitor: Visitor = (edge: Int) => {
index.query(new BBox(…), visitor)

Resources I looked at:

  • I looked at EdgeExplorer, but that needs a node and gives you edges that connect to it. I need the other way around.
  • I also looked at hop.getGraphHopperStorage().getEdgeIteratorStateForKey(123) but I get back edges from the query, not edge keys.
  • There is, of course, the brute force way detailed in How to get EdgeIteratorState from EdgeID - #4 by easbar, that is iterating through all edges of the entire graph and picking put the ones with matching IDs. However, I really hope there is a faster solution.

So: How do I get the connecting nodes of an edge or set of edges? Is there no HashMap from edge ID to EdgeIteratorState?

You can do (in java):

EdgeIteratorState edgeState = hopper.getGraphHopperStorage().getEdgeIteratorState(edge, Integer.MIN_VALUE);
int nodeA = edgeState.getBaseNode();
int nodeB = edgeState.getAdjNode();

NodeAccess na = hopper.getGraphHopperStorage().getNodeAccess();
na.getLat(nodeA); // etc.

Otherwise, yes using LocationIndex like you do is the way to go.

1 Like

Integer.MIN_VALUE, how curious! I don’t think I would have figured that out by myself, thanks! Would you perchance know where this is documented? I feel like there must be some graphhopper core concepts document that I have missed.

This is (only?) written in the java docs of the method in the Graph interface.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.