forked from graphhopper/graphhopper
-
Notifications
You must be signed in to change notification settings - Fork 1
Low Level API
karussell edited this page Apr 29, 2013
·
6 revisions
// Creating and saving the graph
GraphBuilder gb = new GraphBuilder().location("some-folder-gh").store(true);
GraphStorage graph = gb.create();
// Make a weighted edge between two nodes. False means the edge is directed.
graph.edge(fromId, toId, cost, false);
// Store to disc
graph.flush();
// Load graph
GraphStorage graph = gb.load();
// Load index
Location2IDIndex index = new Location2IDQuadtree(graph, dir);
// for newer versions instead do:
// Location2IDIndex index = new Location2NodesNtree(graph, dir);
if (!index.loadExisting())
throw new IllegalStateException("location2id index cannot be loaded!");
// calculate path
int fromId = index.findID(latitudeFrom, longituteFrom);
int toId = index.findID(latitudeTo, longituteTo);
Path path = new DijkstraSimple().calcPath(fromId, toId);
// Creating and saving the graph
GraphBuilder gb = new GraphBuilder().location("some-folder-gh").store(true);
GraphStorage graph = gb.create();
// Make a weighted edge between two nodes. False means the edge is directed.
graph.edge(fromId, toId, cost, false);
// Store to disc
graph.flush();
// Loading and using the graph
GraphStorage graph = gb.load();
Path path = new DijkstraSimple().calcPath(fromId, toId);
// Creating and saving the graph
GraphBuilder gb = new GraphBuilder().location("some-folder-gh").store(true).levelGraph(true);
GraphStorage graph = gb.create();
// Make a weighted edge between two nodes. False means the edge is directed.
graph.edge(fromId, toId, cost, false);
// Prepare the graph for fast querying ...
new PrepareContractionHierarchies().graph(graph).doWork();
graph.flush();
// Loading and using the graph
GraphStorage graph = gb.load();
algorithm = new PrepareContractionHierarchies().graph(graph).createAlgo();
Path path = algorithm.calcPath(fromId, toId);