Skip to content

Commit

Permalink
solve multiple waypoints for geometry_simplify=true, #457
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsnolde authored and Adam Rousell committed Mar 25, 2019
1 parent 53533a7 commit e282075
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> 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));
}
Expand All @@ -68,8 +74,8 @@ RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> 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);
Expand All @@ -78,12 +84,12 @@ RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit e282075

Please sign in to comment.