Skip to content

Commit

Permalink
feat: take into account hazmat:B, ..., hazmat:E tags (#1879)
Browse files Browse the repository at this point in the history
  • Loading branch information
takb authored Oct 31, 2024
2 parents 86c98aa + 549499d commit 687802f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ RELEASING:
7. Adding the corresponding tag is done when releasing via GitHub.
-->
## [unreleased]
### Added
- take into account tunnel categories B, C, D, and E when restricting roads for the transport of dangerous goods via the `hazmat` flag in vehicle parameters ([#1879](https://github.com/GIScience/openrouteservice/pull/1879))
### Changed
- update docs dependency: VitePress ([#1872](https://github.com/GIScience/openrouteservice/pull/1872))
- adjust documentation for export endpoint ([#1872](https://github.com/GIScience/openrouteservice/pull/1872))

### Fixed
- do not enforce a time-dependent routing algorithm unless the weighting requires it ([#1865](https://github.com/GIScience/openrouteservice/pull/1865))
- failing queries that combined departure/arrival parameters with avoid polygons ([#1871](https://github.com/GIScience/openrouteservice/pull/1871))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,52 @@ void testHGVHeightRestriction() {
.statusCode(200);
}

@Test
void testHGVHazmatRestriction() {
JSONObject body = new JSONObject();
body.put("coordinates", HelperFunctions.constructCoords("8.684872,49.40527|8.719071,49.414851"));
body.put("preference", "shortest");
body.put("instructions", false);
body.put("units", "m");

JSONObject restrictions = new JSONObject();
restrictions.put("hazmat", false);
JSONObject params = new JSONObject();
params.put("restrictions", restrictions);
JSONObject options = new JSONObject();
options.put("profile_params", params);
options.put("vehicle_type", "hgv");
body.put("options", options);

given()
.config(JSON_CONFIG_DOUBLE_NUMBERS)
.headers(CommonHeaders.jsonContent)
.pathParam("profile", "driving-hgv")
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}")
.then()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].summary.distance", is(closeTo(2808, 1)))
.statusCode(200);

restrictions.put("hazmat", true);

given()
.config(JSON_CONFIG_DOUBLE_NUMBERS)
.headers(CommonHeaders.jsonContent)
.pathParam("profile", "driving-hgv")
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}")
.then()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].summary.distance", is(closeTo(11359, 1)))
.statusCode(200);
}

@Test
void testCarDistanceAndDuration() {
JSONObject body = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class HeavyVehicleGraphStorageBuilder extends AbstractGraphStorageBuilder
private final Set<String> noValues = new HashSet<>(5);
private final Set<String> yesValues = new HashSet<>(5);
private final Pattern patternDimension;
private final Pattern patternHazmat;

public HeavyVehicleGraphStorageBuilder() {
motorVehicleRestrictions.addAll(Arrays.asList("motorcar", "motor_vehicle", "vehicle", "access"));
Expand All @@ -55,6 +56,7 @@ public HeavyVehicleGraphStorageBuilder() {
yesValues.addAll(Arrays.asList("yes", "designated"));

patternDimension = Pattern.compile("(?:\\s*(\\d+)\\s*(?:feet|ft\\.|ft|'))?(?:(\\d+)\\s*(?:inches|in\\.|in|''|\"))?");
patternHazmat = Pattern.compile("^hazmat(:[B-E])?$");
}

public GraphExtension init(GraphHopper graphhopper) throws Exception {
Expand Down Expand Up @@ -183,7 +185,7 @@ public void processWay(ReaderWay way) {
setAccessFlags(vehicleType, accessValue);
if (vehicleType.equals(value))// e.g. hgv=delivery implies that hgv other than delivery vehicles are blocked
setAccessFlags(key, "no");
} else if (key.equals("hazmat") && "no".equals(value)) {
} else if (patternHazmat.matcher(key).matches() && "no".equals(value)) {
hgvType |= HeavyVehicleAttributes.HAZMAT;
}
}
Expand Down

0 comments on commit 687802f

Please sign in to comment.