I tried to use osm2po as a library and write a simple routing program based on the sample code at (http://osm2po.de/)
However, when I try to load the .pbf file into the data structure "Graph". The eclipse, the IDE that I used, shows the error message as following: "Exception in thread "main" java.lang.RuntimeException: No osm2po-GraphFile"
Can anyone tell me what's going wrong when I try to load "C:\taiwan-latest.osm.pbf"?
//=========== the full code of the simple routing program is listed below:
public static void main(String[] args){
File graphFile = new File("C:\\taiwan-latest.osm.pbf");
Graph graph = new Graph(graphFile);
DefaultRouter router = new DefaultRouter();
// Somewhere in Hamburg
int sourceId = graph.findClosestVertexId(25.033839f, 121.565064f);
int targetId = graph.findClosestVertexId(25.040135f, 121.560328f);
// Possible additional params for DefaultRouter
Properties params = new Properties();
params.setProperty("findShortestPath", "false");
params.setProperty("ignoreRestrictions", "false");
params.setProperty("ignoreOneWays", "false");
params.setProperty("heuristicFactor", "1.0"); // 0.0 Dijkstra, 1.0 good A*
int[] path = router.findPath(
graph, sourceId, targetId, Float.MAX_VALUE, params);
if (path != null) { // Found!
for (int i = 0; i < path.length; i++) {
RoutingResultSegment rrs = graph.lookupSegment(path[i]);
int segId = rrs.getId();
int from = rrs.getSourceId();
int to = rrs.getTargetId();
String segName = rrs.getName().toString();
System.out.println(from + "-" + to + " " + segId + "/" + path[i] + " " + segName);
}
}
graph.close();
}