Hiya, so here is where I’m currently at - This processes 896 relations in 3 seconds using a single thread.
I suppose not a perfect implementation but it is a quick way to do an initial assessment to see if current p1 -> p442 is less than 300m then use it in the matrix, if not then exclude.
This means that it takes ~4 seconds (guestimate) to go from 1,042,441 points to 109,128 points.
Note that createLargePointSet is cut down in size to reduce post size.
import com.graphhopper.routing.Dijkstra;
import com.graphhopper.routing.Path;
import com.graphhopper.routing.querygraph.QueryGraph;
import com.graphhopper.routing.util.EdgeFilter;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.util.FlagEncoderFactory;
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.GraphHopperStorage;
import static com.graphhopper.routing.util.TraversalMode.EDGE_BASED;
import com.graphhopper.routing.weighting.ShortestWeighting;
import com.graphhopper.storage.index.LocationIndexTree;
import com.graphhopper.storage.index.QueryResult;
import com.graphhopper.util.shapes.GHPoint;
public class tester {
private static FlagEncoder carEncoder;
private static EncodingManager em;
private static Weighting defaultWeighting;
public static void main(String[] args) throws Exception {
testGraph();
}
public static void testGraph() {
GHPoint[] points = createLargePointSet();
em = EncodingManager.create(FlagEncoderFactory.FOOT + "|block_private=false," + FlagEncoderFactory.BIKE + "," + FlagEncoderFactory.BIKE2 + "," + FlagEncoderFactory.CAR);
GraphHopperStorage graph = createStorage(em);
graph.loadExisting();
LocationIndexTree index = new LocationIndexTree(graph, graph.getDirectory());
index.prepareIndex();
carEncoder = em.getEncoder("car");
defaultWeighting = new ShortestWeighting(carEncoder);
graph.freeze();
Weighting w = defaultWeighting;
long startNano = System.currentTimeMillis();
System.out.println(points.length + " Points");
for (int i = 0; i < points.length-1; i++) {
QueryResult fromSnap = index.findClosest(points[i].getLat(), points[i].getLon(), EdgeFilter.ALL_EDGES);
QueryResult toSnap = index.findClosest(points[i+1].getLat(), points[i+1].getLon(), EdgeFilter.ALL_EDGES);
QueryGraph queryGraph = QueryGraph.create(graph, fromSnap, toSnap);
Path path = new Dijkstra(queryGraph, w, EDGE_BASED).calcPath(fromSnap.getClosestNode(), toSnap.getClosestNode());
}
long endNano = System.currentTimeMillis();
System.out.println("Done in "+(endNano - startNano)/ 1000+" seconds");
}
private static GraphHopperStorage createStorage(EncodingManager em) {
GraphHopperStorage ghStorage = new GraphBuilder(em).setRAM("C:\\Program Files\\ETL Data Load Processes\\nz_latest_gh\\", true).set3D(true).build();
return ghStorage;
}
public static GHPoint[] createLargePointSet() {
return new GHPoint[] {
new GHPoint(-41.22179883, 174.806107),
new GHPoint(-41.22195814, 174.8058141),
new GHPoint(-41.22193542, 174.805821),
new GHPoint(-41.22190838, 174.8058292)
};
}
}