Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.51 KB

java.md

File metadata and controls

35 lines (27 loc) · 1.51 KB

Isochrone via Java API

To use the following examples you need to specify the dependency in your Maven config correctly.

To create an isochrone in Java code:

You'll first need to build off an existing Graphhopper instance for routing.

Next, compute the isochrone itself.

// get encoder from GraphHopper instance
EncodingManager encodingManager = hopper.getEncodingManager();
FlagEncoder encoder = encodingManager.getEncoder("car");

// snap some GPS coordinates to the routing graph and build a query graph
QueryResult qr = hopper.getLocationIndex().findClosest(lat, lon, DefaultEdgeFilter.allEdges(encoder));
QueryGraph queryGraph = QueryGraph.create(hopper.getGraphHopperStorage(), qr);

// run the isochrone calculation
ShortestPathTree tree = new ShortestPathTree(queryGraph, new FastestWeighting(encoder), false, TraversalMode.NODE_BASED);
// find all nodes that are within a radius of 60s
tree.setTimeLimit(60_000);
// you need to specify a callback to define what should be done 
tree.search(qr.getClosestNode(),  label -> {
    // see IsoLabel.java for more properties
    System.out.println("node: " + label.node);
    System.out.println("time: " + label.time);
    System.out.println("distance: " + label.distance);
});

See IsochroneResource.java to find out how to create an iso line polygone / isochrone from using the shortest path tree.