Graphhopper: ClassCastException when calculating path with CH Astar/Dikstra Bi -
using wgs84 coordinates can write graph , index disk. in java project read graph , index disk. works fine following code.
flagencoder encoder = new carflagencoder(); encodingmanager em = new encodingmanager(encoder); graphbuilder gb = new graphbuilder(em). setlocation(testdir). setstore(true). setchgraph(new fastestweighting(encoder)); // load , use graph graphhopperstorage graph = gb.load(); // load index locationindex index = new locationindextree(graph.getbasegraph(), graph.getdirectory()); if (!index.loadexisting()) throw new illegalstateexception("location index cannot loaded!"); algorithmoptions algoopts = algorithmoptions.start().algorithm(parameters.algorithms.astar_bi). traversalmode(traversalmode.node_based). weighting(new fastestweighting(encoder)). build(); preparecontractionhierarchies pch = new preparecontractionhierarchies(graph.getdirectory(), graph, graph.getgraph(chgraphimpl.class), new fastestweighting(encoder), traversalmode.node_based); pch.dowork(); queryresult fromqr = index.findclosest(fromcoordinate.x, fromcoordinate.y, edgefilter.all_edges); queryresult toqr = index.findclosest(tocoordinate.x, tocoordinate.y, edgefilter.all_edges); querygraph querygraph = new querygraph(graph); querygraph.lookup(fromqr, toqr); routingalgorithm algorithm = pch.createalgo(querygraph, algoopts); path path = algorithm.calcpath(fromqr.getclosestnode(), toqr.getclosestnode());
however, first wonder why preparation of contraction hierarchies needs time. have expected preparation had been done already. done again? what's purpose of file named "shortcuts_fastest_car"?
second, receive confusing classcastexception
once algorithm.calcpath
called.
exception in thread "main" java.lang.classcastexception: com.graphhopper.storage.basegraph$edgeiterable cannot cast com.graphhopper.util.chedgeiteratorstate @ com.graphhopper.routing.util.leveledgefilter.accept(leveledgefilter.java:48) @ com.graphhopper.routing.abstractroutingalgorithm.accept(abstractroutingalgorithm.java:79) @ com.graphhopper.routing.astarbidirection.filledges(astarbidirection.java:217) @ com.graphhopper.routing.astarbidirection.filledgesfrom(astarbidirection.java:194) @ com.graphhopper.routing.abstractbidiralgo.runalgo(abstractbidiralgo.java:68) @ com.graphhopper.routing.abstractbidiralgo.calcpath(abstractbidiralgo.java:61)
what's going wrong? there config flag missing?
i think have pass ch graph
graph.getgraph(chgraphimpl.class)
instead of graph
querygraph constructor.
Comments
Post a Comment