Question on how to access the Graph Object

Hello,
i am quiet new to graphhopper i saw in the Technical Overview the description of the Graph data layout. I tried for the past few days to get access to it. I have an osm file loaded and can do routing requests using the given commands. What i cant find is on how to directly access the mentioned Graph to directly work with it eg. extract all neighbors(nodes) for a given node. Feedback is appriciated.
BG,
J

So are you using GraphHopper via the Java API? If you have the GraphHopper object you can for example do this:

// I assume you do this somewhere
GraphHopper hopper ...
// get the graph
Graph graph = hopper.getGraphHopperStorage();
// e.g. explore the edges/nodes adjacent to some node x
int x = 42;
EdgeExplorer explorer = graph.createEdgeExplorer();
EdgeIterator iter = explorer.setBaseNode(x);
while (iter.next()) {
   assertEquals(x, iter.getBaseNode());
   // this is the adjacent edge's ID
   int edge = iter.getEdge();
   // this is the neighboring node
   int adjNode = iter.getAdjNode();
}
1 Like