private static Response.ResponseBuilder gpxSuccessResponseBuilder(GHResponse ghRsp, String timeString, String trackName, boolean enableElevation, boolean withRoute, boolean withTrack, boolean withWayPoints, String version) { if (ghRsp.getAll().size() > 1) { throw new IllegalArgumentException("Alternatives are currently not yet supported for GPX"); } long time = timeString != null ? Long.parseLong(timeString) : System.currentTimeMillis(); return Response.ok(ghRsp.getBest().getInstructions().createGPX(trackName, time, enableElevation, withRoute, withTrack, withWayPoints, version), "application/gpx+xml"). header("Content-Disposition", "attachment;filename=" + "GraphHopper.gpx"); }
} else { logger.info(logStr + ", alternatives: " + ghResponse.getAll().size() + ", distance0: " + ghResponse.getBest().getDistance() + ", weight0: " + ghResponse.getBest().getRouteWeight() + ", time0: " + Math.round(ghResponse.getBest().getTime() / 60000f) + "min" + ", points0: " + ghResponse.getBest().getPoints().getSize() + ", debugInfo: " + ghResponse.getDebugInfo()); return writeGPX ?
String infoStr = " weight:" + lmRsp.getBest().getRouteWeight() + ", original: " + originalRsp.getBest().getRouteWeight() + " distance:" + lmRsp.getBest().getDistance() + ", original: " + originalRsp.getBest().getDistance() + " time:" + round2(lmRsp.getBest().getTime() / 1000) + ", original: " + round2(originalRsp.getBest().getTime() / 1000) + " points:" + lmRsp.getBest().getPoints().size() + ", original: " + originalRsp.getBest().getPoints().size(); if (Math.abs(1 - lmRsp.getBest().getRouteWeight() / originalRsp.getBest().getRouteWeight()) > 0.000001) logger.error("Too big weight difference for LM. " + locStr + infoStr);
" weight:" + noSodRsp.getBest().getRouteWeight() + ", original: " + sodRsp.getBest().getRouteWeight() + " distance:" + noSodRsp.getBest().getDistance() + ", original: " + sodRsp.getBest().getDistance() + " time:" + round2(noSodRsp.getBest().getTime() / 1000) + ", original: " + round2(sodRsp.getBest().getTime() / 1000) + " points:" + noSodRsp.getBest().getPoints().size() + ", original: " + sodRsp.getBest().getPoints().size(); if (Math.abs(1 - noSodRsp.getBest().getRouteWeight() / sodRsp.getBest().getRouteWeight()) > 0.000001) logger.error("Too big weight difference for SOD. " + locStr + infoStr);
PathWrapper arsp = rsp.getBest(); if (!warmup) { visitedNodesSum.addAndGet(rsp.getHints().getLong("visited_nodes.sum", 0));
protected PathWrapper doInBackground(Void... v) { StopWatch sw = new StopWatch().start(); GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon). setAlgorithm(Algorithms.DIJKSTRA_BI); req.getHints(). put(Routing.INSTRUCTIONS, "false"); GHResponse resp = hopper.route(req); time = sw.stop().getSeconds(); return resp.getBest(); }
@Test public void testDisconnected179() { GraphHopperStorage graph = new GraphBuilder(encodingManager).create(); initGraph(graph); GraphHopper instance = new GraphHopper(). setStoreOnFlush(false). setEncodingManager(encodingManager).setCHEnabled(false). loadGraph(graph); GHResponse rsp = instance.route(new GHRequest(42, 10, 42, 10.4)); assertTrue(rsp.hasErrors()); try { rsp.getBest().getPoints(); assertTrue(false); } catch (Exception ex) { } instance.close(); }
@Test public void testLoad() { GraphHopperStorage graph = new GraphBuilder(encodingManager).create(); initGraph(graph); // do further changes: NodeAccess na = graph.getNodeAccess(); na.setNode(4, 41.9, 10.2); graph.edge(1, 2, 10, false); graph.edge(0, 4, 40, true); graph.edge(4, 3, 40, true); GraphHopper instance = new GraphHopper(). setStoreOnFlush(false). setEncodingManager(encodingManager).setCHEnabled(false). loadGraph(graph); // 3 -> 0 GHResponse rsp = instance.route(new GHRequest(42, 10.4, 42, 10)); assertFalse(rsp.hasErrors()); PathWrapper arsp = rsp.getBest(); assertEquals(80, arsp.getDistance(), 1e-6); PointList points = arsp.getPoints(); assertEquals(42, points.getLatitude(0), 1e-5); assertEquals(10.4, points.getLongitude(0), 1e-5); assertEquals(41.9, points.getLatitude(1), 1e-5); assertEquals(10.2, points.getLongitude(1), 1e-5); assertEquals(3, points.getSize()); instance.close(); }
GHPoint prev = null; List<GPXEntry> mock = new ArrayList<>(); PointList points = r.getBest().getPoints();
time = measurements.get(0).getTime(); return Response.ok(rsp.getBest().getInstructions().createGPX(gpx.trk.get(0).name != null ? gpx.trk.get(0).name : "", time, enableElevation, withRoute, withTrack, false, Constants.VERSION), "application/gpx+xml"). header("X-GH-Took", "" + Math.round(took * 1000)). build();
public RoutingResult getRouteBetween(NavigationPosition from, NavigationPosition to, TravelMode travelMode) { initializeHopper(); long start = currentTimeMillis(); try { GHRequest request = new GHRequest(from.getLatitude(), from.getLongitude(), to.getLatitude(), to.getLongitude()); request.setVehicle(travelMode.getName().toUpperCase()); GHResponse response = hopper.route(request); if(response.hasErrors()) { String errors = printArrayToDialogString(response.getErrors().toArray(), false); log.severe(format("Error while routing between %s and %s: %s", from, to, errors)); throw new RuntimeException(errors); } PathWrapper best = response.getBest(); return new RoutingResult(asPositions(best.getPoints()), new DistanceAndTime(best.getDistance(), best.getTime() / 1000), true); } finally { long end = currentTimeMillis(); log.info("GraphHopper: routing from " + from + " to " + to + " took " + (end - start) + " milliseconds"); } }