2

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();
}

1 Answer 1

1

Your taiwan-latest.osm.pbf only contains raw OpenStreetMap-Data in a structured compressed binary format (pbf). It must be converted in order to produce a routable graph-file (*.gph) for osm2po or for pgRouting (*.sql). Please read the online-help or start the demo.bat / demo.sh to see how it works and to generate your first *.gph-File you can play with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.