From e282075def2226e7085a6b35e1354b534c89370e Mon Sep 17 00:00:00 2001 From: nilsnolde Date: Wed, 20 Mar 2019 16:07:00 +0300 Subject: [PATCH] solve multiple waypoints for geometry_simplify=true, #457 --- CHANGELOG.md | 2 +- .../ors/services/routing/ParamsTest.java | 3 ++- .../ors/v2/services/routing/ParamsTest.java | 22 ------------------- .../ors/v2/services/routing/ResultTest.java | 6 ++--- .../requests/routing/RouteRequestHandler.java | 3 --- .../ors/routing/RouteResultBuilder.java | 10 +++++++-- .../RoutingRequestParser.java | 2 -- 7 files changed, 14 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee669bbe63..62ee784d0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Makes docker and docker-compose deployment of openrouteservice more customizable (Issue #434) ### Fixed -- +- Enable > 2 waypoints when geometry_simplify=true (#457) ### Changed - Updated pom to always build ors.war (Issue #432) ### Deprecated diff --git a/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ParamsTest.java b/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ParamsTest.java index 65443e543b..a99db92c2e 100644 --- a/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ParamsTest.java +++ b/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ParamsTest.java @@ -36,6 +36,7 @@ public ParamsTest() { addParameter("coordinatesShort", "8.678613,49.411721|8.687782,49.424597"); addParameter("coordinatesShortFaulty", "8.680916a,49.41b0973|8.6c87782,049gbd.424597"); addParameter("coordinatesLong", "8.678613,49.411721|4.78906,53.071752"); + addParameter("coordinatesShortThree", "8.678613,49.411721|8.687782,49.424597|8.691087,49.425009"); addParameter("extra_info", "surface|suitability|steepness"); addParameter("preference", "fastest"); addParameter("profile", "cycling-regular"); @@ -729,7 +730,7 @@ public void expectSuppressedWarnings() { @Test public void expectSimplifyGeometry() { given() - .param("coordinates", getParameter("coordinatesShort")) + .param("coordinates", getParameter("coordinatesShortThree")) .param("profile", getParameter("carProfile")) .param("geometry_simplify", "true") .when() diff --git a/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ParamsTest.java b/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ParamsTest.java index 746a0d7ea9..db4f7d6b10 100644 --- a/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ParamsTest.java +++ b/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ParamsTest.java @@ -1338,26 +1338,4 @@ public void expectSkipSegmentsWarnings() { .body("features[0].properties.warnings[0].containsKey('message')", is(true)) .statusCode(200); } - - @Test - public void expectErrorWithMultiSegmentsAndSimplify() { - JSONArray coords = (JSONArray) getParameter("coordinatesShort"); - coords.put(new JSONArray(new double[] {8.680916, 49.410973})); - - JSONObject body = new JSONObject(); - body.put("coordinates", coords); - body.put("geometry_simplify", true); - - given() - .header("Accept", "application/json") - .header("Content-Type", "application/json") - .pathParam("profile", getParameter("carProfile")) - .body(body.toString()) - .when().log().all() - .post(getEndPointPath() + "/{profile}/json") - .then().log().all() - .assertThat() - .body("error.code", is(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS)) - .statusCode(400); - } } diff --git a/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java b/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java index 5e0c767601..17d4f4d489 100644 --- a/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java +++ b/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java @@ -1817,7 +1817,7 @@ public void testAccessRestrictionsWarnings() { @Test public void testSimplifyHasLessWayPoints() { JSONObject body = new JSONObject(); - body.put("coordinates", getParameter("coordinatesShort")); + body.put("coordinates", getParameter("coordinatesLong")); given() .header("Accept", "application/geo+json") @@ -1828,7 +1828,7 @@ public void testSimplifyHasLessWayPoints() { .post(getEndPointPath() + "/{profile}/geojson") .then().log().all() .assertThat() - .body("features[0].geometry.coordinates.size()", is(75)) + .body("features[0].geometry.coordinates.size()", is(534)) .statusCode(200); body.put("geometry_simplify", true); @@ -1842,7 +1842,7 @@ public void testSimplifyHasLessWayPoints() { .post(getEndPointPath() + "/{profile}/geojson") .then().log().all() .assertThat() - .body("features[0].geometry.coordinates.size()", is(34)) + .body("features[0].geometry.coordinates.size()", is(299)) .statusCode(200); } diff --git a/openrouteservice/src/main/java/heigit/ors/api/requests/routing/RouteRequestHandler.java b/openrouteservice/src/main/java/heigit/ors/api/requests/routing/RouteRequestHandler.java index 66adca6106..9979289a29 100644 --- a/openrouteservice/src/main/java/heigit/ors/api/requests/routing/RouteRequestHandler.java +++ b/openrouteservice/src/main/java/heigit/ors/api/requests/routing/RouteRequestHandler.java @@ -97,9 +97,6 @@ public RoutingRequest convertRouteRequest(RouteRequest request) throws StatusCo if (request.hasExtraInfo() && request.getSimplifyGeometry()) { throw new IncompatibleParameterException(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS, RouteRequest.PARAM_SIMPLIFY_GEOMETRY, "true", RouteRequest.PARAM_EXTRA_INFO, "*"); } - if (request.getCoordinates().size() > 2 && request.getSimplifyGeometry()) { - throw new IncompatibleParameterException(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS, RouteRequest.PARAM_SIMPLIFY_GEOMETRY, "true", RouteRequest.PARAM_COORDINATES, "count > 2"); - } } if (request.hasSkipSegments()) { diff --git a/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java index 1dd3c50163..222e78f03c 100644 --- a/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java +++ b/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java @@ -53,6 +53,12 @@ RouteResult createMergedRouteResultFromBestPaths(List responses, Rou RouteResult result = new RouteResult(request.getExtraInfo()); result.addExtras(request, extras); + int allPointsSize = 0; + for (GHResponse resp : responses) { + allPointsSize =+ resp.getBest().getPoints().size(); + }; + PointList pointsToAdd = new PointList(allPointsSize, false); + if (request.getSkipSegments() != null && !request.getSkipSegments().isEmpty()) { result.addWarning(new RouteWarning(RouteWarning.SKIPPED_SEGMENTS)); } @@ -68,8 +74,8 @@ RouteResult createMergedRouteResultFromBestPaths(List responses, Rou throw new InternalServerException(RoutingErrorCodes.UNKNOWN, String.format("Unable to find a route between points %d (%s) and %d (%s)", ri, FormatUtility.formatCoordinate(request.getCoordinates()[ri]), ri + 1, FormatUtility.formatCoordinate(request.getCoordinates()[ri + 1]))); PathWrapper path = response.getBest(); + pointsToAdd.add(path.getPoints()); - result.addPointlist(path.getPoints()); if (request.getIncludeGeometry()) { result.addPointsToGeometry(path.getPoints(), ri > 0, request.getIncludeElevation()); result.addWayPointIndex(result.getGeometry().length - 1); @@ -78,12 +84,12 @@ RouteResult createMergedRouteResultFromBestPaths(List responses, Rou result.addSegment(createRouteSegment(path, request, getNextResponseFirstStepPoints(responses, ri))); } + result.addPointlist(pointsToAdd); result.calculateRouteSummary(request); if (!request.getIncludeGeometry() || !request.getIncludeInstructions()) { result.resetSegments(); } - return result; } diff --git a/openrouteservice/src/main/java/heigit/ors/services/routing/requestprocessors/RoutingRequestParser.java b/openrouteservice/src/main/java/heigit/ors/services/routing/requestprocessors/RoutingRequestParser.java index 4471e8287a..f5be3a28ae 100644 --- a/openrouteservice/src/main/java/heigit/ors/services/routing/requestprocessors/RoutingRequestParser.java +++ b/openrouteservice/src/main/java/heigit/ors/services/routing/requestprocessors/RoutingRequestParser.java @@ -180,8 +180,6 @@ public static RoutingRequest parseFromRequestParams(HttpServletRequest request) value = request.getParameter("geometry_simplify"); if (!Helper.isEmpty(value)) - if (req.getCoordinates().length > 2 ) - throw new IncompatibleParameterException(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS, "geometry_simplify", "true", "coordinates", "count > 2"); req.setGeometrySimplify(Boolean.parseBoolean(value)); value = request.getParameter("instructions");