+ took + ", " + algoStr + ", " + weighting + ", " + vehicleStr; if (ghResponse.hasErrors()) { logger.error(logStr + ", errors:" + ghResponse.getErrors()); throw new MultiException(ghResponse.getErrors());
@Override public GHResponse route(GHRequest request) { ResponseBody rspBody = null; try { Request okRequest = createRequest(request); rspBody = getClientForRequest(request).newCall(okRequest).execute().body(); JsonNode json = objectMapper.reader().readTree(rspBody.byteStream()); GHResponse res = new GHResponse(); res.addErrors(readErrors(json)); if (res.hasErrors()) return res; JsonNode paths = json.get("paths"); boolean tmpElevation = request.getHints().getBool("elevation", elevation); boolean tmpTurnDescription = request.getHints().getBool("turn_description", true); for (JsonNode path : paths) { PathWrapper altRsp = createPathWrapper(path, tmpElevation, tmpTurnDescription); res.add(altRsp); } return res; } catch (Exception ex) { throw new RuntimeException("Problem while fetching path " + request.getPoints() + ": " + ex.getMessage(), ex); } finally { Helper.close(rspBody); } }
if (rsp.hasErrors()) { if (!warmup) failedCount.incrementAndGet();
List<QueryResult> qResults = routingTemplate.lookup(points, encoder); ghRsp.addDebugInfo("idLookup:" + sw.stop().getSeconds() + "s"); if (ghRsp.hasErrors()) return Collections.emptyList();
@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(); }
public GHResponse getResponse(GHPoint from, GHPoint to) { // The flag encoder's toString method returns the vehicle type GHRequest req = new GHRequest(from, to).setVehicle(flagEncoder.toString()); GHResponse rsp = hopper.route(req); if (rsp.hasErrors()) { return null; } return rsp; }
if (!r.hasErrors()) { long time = 0; double sampleProportion = rand.nextDouble();
public class GraphHopperWithPaths extends GraphHopper { public List<Integer> routePaths(double startY, double startX, double endY, double endX){ //Examine a route and return edgeIDs that GraphHopper uses LocationIndex index = this.getLocationIndex(); GHRequest request = new GHRequest(startY, startX, endY, endX); GHResponse response = new GHResponse(); List<Path> paths = getPaths(request, response); List<Integer> edges = new ArrayList<Integer>(); for(Path p:paths){ for(EdgeIteratorState e:p.calcEdges()){ edges.add(e.getEdge()); } } if (response.hasErrors()) return null; //Get edges for start and end point as well QueryResult qr = index.findClosest(startY, startX, EdgeFilter.ALL_EDGES ); edges.add(qr.getClosestEdge().getEdge()); qr = index.findClosest(endY, endX, EdgeFilter.ALL_EDGES ); edges.add(qr.getClosestEdge().getEdge()); return edges; } }
GHRequest req = new GHRequest(32.070113, 34.790266, 32.067103, 34.777861) .setWeighting("fastest") .setVehicle("car"); GHResponse res = gh.route(req); if(res.hasErrors()) { // handle or throw exceptions res.getErrors() return; } // get path geometry information (latitude, longitude and optionally elevation) PointList pl = res.getPoints(); // distance of the full path, in meter double distance = res.getDistance(); // time of the full path, in milliseconds long millis = res.getTime(); // get information per turn instruction InstructionList il = res.getInstructions();
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"); } }
List<QueryResult> qResults = routingTemplate.lookup(points, encoder); ghRsp.addDebugInfo("idLookup:" + sw.stop().getSeconds() + "s"); if (ghRsp.hasErrors()) return Collections.emptyList();
List<QueryResult> qResults = routingTemplate.lookup(points, encoder); ghRsp.addDebugInfo("idLookup:" + sw.stop().getSeconds() + "s"); if (ghRsp.hasErrors()) return Collections.emptyList();
qResults = routingTemplate.lookup(points, encoder); ghRsp.addDebugInfo("idLookup:" + sw.stop().getSeconds() + "s"); if (ghRsp.hasErrors()) return Collections.emptyList();