I tried to use osm2po as a library and to write a simple routing program based on the sample code listed inat (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 tellstell me what's going wrong when I tryiedtry to load "C:\taiwan-latest.osm.pbf"?
//=========== the full codescode of the simple routing program areis listed below: public static void main(String[] args){
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();
}