Skip to content

Commit

Permalink
feature-#418 snapping distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Psotta committed Mar 26, 2019
1 parent c2f0aa5 commit 9c49e11
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- Makes docker and docker-compose deployment of openrouteservice more customizable (Issue #434)
- Add the possibility to predefine standard maximum search radii in general and for each used profile in the config file (Issue #418)
### Fixed
- Updated documentation to reflect correct isochrone smoothing algorithm (Issue #471)
- Enable > 2 waypoints when geometry_simplify=true (#457)
Expand Down
6 changes: 4 additions & 2 deletions openrouteservice-api-tests/conf/app.config.test
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
instructions: true,
maximum_distance: 100000,
maximum_segment_distance_with_dynamic_weights: 50000,
maximum_waypoints: 50

maximum_waypoints: 50,
maximum_snapping_radius: 350,
preparation:
{
min_network_size: 200,
Expand Down Expand Up @@ -203,6 +203,7 @@
parameters: {
encoder_options: "consider_elevation=false|turn_costs=true|block_fords=false",
elevation: true,
maximum_snapping_radius: 10,
ext_storages: {
WayCategory: {},
WaySurfaceType: {},
Expand Down Expand Up @@ -295,6 +296,7 @@
parameters: {
encoder_options: "block_fords=true",
elevation: true,
maximum_snapping_radius: 50,
ext_storages: {
Wheelchair: {
KerbsOnCrossings: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,4 +1338,110 @@ public void expectSkipSegmentsWarnings() {
.body("features[0].properties.warnings[0].containsKey('message')", is(true))
.statusCode(200);
}

/**
* This test needs the maximum_snapping_radius of cycling-regular to be >= 10 and <= 100
* and maximum_snapping_radius of the default parameters to be >= 350 in the test config to run through.
*/
@Test
public void expectPointNotFoundError() {

JSONArray coords = new JSONArray();
coords.put(new JSONArray(new double[]{8.688544, 49.435462}));
coords.put(new JSONArray(new double[]{8.678727, 49.440115}));

JSONObject body = new JSONObject();
body.put("coordinates", coords);

given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", "cycling-regular")
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.statusCode(200);
body.put("radiuses", new int[]{5, 10});

given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", "cycling-regular")
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.POINT_NOT_FOUND))
.statusCode(404);

coords = new JSONArray();
coords.put(new JSONArray(new double[]{8.688297, 49.436299}));
coords.put(new JSONArray(new double[]{8.678727, 49.440115}));

body = new JSONObject();
body.put("coordinates", coords);

given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", "cycling-regular")
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.POINT_NOT_FOUND))
.statusCode(404);

body.put("radiuses", new int[]{100, 10});

given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", "cycling-regular")
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.POINT_NOT_FOUND))
.statusCode(404);

coords = new JSONArray();
coords.put(new JSONArray(new double[]{8.647348, 49.366612}));
coords.put(new JSONArray(new double[]{8.678727, 49.440115}));

body = new JSONObject();
body.put("coordinates", coords);

given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", "driving-car")
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.statusCode(200);

body.put("radiuses", new int[]{150, 10});

given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", "driving-car")
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.POINT_NOT_FOUND))
.statusCode(404);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ public RouteResult computeRoute(RoutingRequest req) throws Exception {
EdgeFilter customEdgeFilter = rp.createAccessRestrictionFilter(coords);
GHResponse prevResp = null;
WayPointBearing[] bearings = (req.getContinueStraight() || searchParams.getBearings() != null) ? new WayPointBearing[2] : null;
double[] radiuses = searchParams.getMaximumRadiuses() != null ? new double[2] : null;
int profileType = req.getSearchParameters().getProfileType();
double[] radiuses;
if (searchParams.getMaximumRadiuses() != null) {
radiuses = new double[2];
} else if (_routeProfiles.getRouteProfile(profileType).getConfiguration().hasMaximumSnappingRadius()) {
radiuses = new double[2];
} else {
radiuses = null;
}

for (int i = 1; i <= nSegments; ++i) {
c1 = coords[i];
Expand All @@ -385,8 +393,21 @@ public RouteResult computeRoute(RoutingRequest req) throws Exception {
if (searchParams.getMaximumRadiuses() != null) {
radiuses[0] = searchParams.getMaximumRadiuses()[i - 1];
radiuses[1] = searchParams.getMaximumRadiuses()[i];
}else {
try {
int maximumSnappingRadius = _routeProfiles.getRouteProfile(profileType).getConfiguration().getMaximumSnappingRadius();
radiuses[0] = maximumSnappingRadius;
radiuses[1] = maximumSnappingRadius;
} catch (Exception ex) {
}

}

// else {
// _routeProfiles.getUniqueProfiles().get()
// mInstance.getProfiles()
// }

GHResponse gr;
if ((skipSegments.contains(i))) {
gr = rp.computeRoute(c0.y, c0.x, c1.y, c1.x, bearings, radiuses, true, searchParams, customEdgeFilter, routeProcCntx, req.getGeometrySimplify());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public class RouteProfileConfiguration
private String _elevationCachePath = null;
private String _elevationDataAccess = "MMAP";
private boolean _elevationCacheClear = true;
private int _maximumSnappingRadius;

private Envelope _extent;

private boolean _hasMaximumSnappingRadius = false;

public RouteProfileConfiguration()
{
_extStorages = new HashMap<String, Map<String, String>>();
Expand Down Expand Up @@ -103,7 +105,9 @@ public RouteProfileConfiguration clone()
rpc._elevationCacheClear = this._elevationCacheClear;
rpc._elevationProvider = this._elevationProvider;
rpc._elevationDataAccess = this._elevationDataAccess;


rpc._maximumSnappingRadius = this._maximumSnappingRadius;

rpc._extent = this._extent;

return rpc;
Expand Down Expand Up @@ -312,4 +316,17 @@ public boolean getOptimize() {
public void setOptimize(boolean optimize) {
this._optimize = optimize;
}

public boolean hasMaximumSnappingRadius() {
return _hasMaximumSnappingRadius;
}

public int getMaximumSnappingRadius() {
return _maximumSnappingRadius;
}

public void setMaximumSnappingRadius(int _maximumSnappingRadius) {
this._maximumSnappingRadius = _maximumSnappingRadius;
this._hasMaximumSnappingRadius = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ else if (defaultParams != null)
if (bbox.size() != 4)
throw new Exception("'extent' element must contain 4 elements.");
profile.setExtent(new Envelope(bbox.get(0),bbox.get(1),bbox.get(2),bbox.get(3)));
break;
case "maximum_snapping_radius":
profile.setMaximumSnappingRadius(Integer.parseInt(paramItem.getValue().toString()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,6 @@ public static RoutingRequest parseFromRequestParams(HttpServletRequest request)
throw new ParameterValueException(RoutingErrorCodes.INVALID_PARAMETER_VALUE, "radiuses", value);

req.getSearchParameters().setMaximumRadiuses(radiuses);
} else {
if(searchParams.getProfileType() == RoutingProfileType.WHEELCHAIR) {
// As there are generally less ways that can be used as pedestrian ways, we need to restrict search
// radii else we end up with starting and ending ways really far from the actual points. This is
// especially a problem for wheechair users as the restrictions are stricter
final int coordinateCount = req.getCoordinates().length;
double maxRadii[] = new double[coordinateCount];
for(int i=0; i<coordinateCount; i++) {
maxRadii[i] = 50;
}

req.getSearchParameters().setMaximumRadiuses(maxRadii);
}
}

value = request.getParameter("units");
Expand Down
4 changes: 3 additions & 1 deletion openrouteservice/src/main/resources/app.config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"maximum_distance": 100000,
"maximum_segment_distance_with_dynamic_weights": 50000,
"maximum_waypoints": 50,

"maximum_snapping_radius": 400,
"preparation": {
"min_network_size": 200,
"min_one_way_network_size": 200,
Expand Down Expand Up @@ -90,6 +90,7 @@
"encoder_options": "turn_costs=true|block_fords=false|use_acceleration=false",
"maximum_distance": 100000,
"elevation": true,
"maximum_snapping_radius": 350,
"preparation": {
"min_network_size": 200,
"min_one_way_network_size": 200,
Expand Down Expand Up @@ -258,6 +259,7 @@
"parameters": {
"encoder_options": "block_fords=true",
"elevation": true,
"maximum_snapping_radius": 50,
"ext_storages": {
"WayCategory": {},
"WaySurfaceType": {},
Expand Down

0 comments on commit 9c49e11

Please sign in to comment.