From 549499de33d37ee682a22257ba5c9e2ec48d8861 Mon Sep 17 00:00:00 2001 From: aoles Date: Thu, 31 Oct 2024 10:47:16 +0100 Subject: [PATCH] feat: take into account `hazmat:B`, ..., `hazmat:E` tags for the restriction of transporting dangerous goods --- CHANGELOG.md | 3 +- .../ors/apitests/routing/ResultTest.java | 46 +++++++++++++++++++ .../HeavyVehicleGraphStorageBuilder.java | 4 +- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91347d4894..992d7504ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java b/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java index 1aa769bf08..680db2805d 100644 --- a/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java +++ b/ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java @@ -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(); diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java index 6f8e64bc60..a9e61e7204 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java @@ -40,6 +40,7 @@ public class HeavyVehicleGraphStorageBuilder extends AbstractGraphStorageBuilder private final Set noValues = new HashSet<>(5); private final Set yesValues = new HashSet<>(5); private final Pattern patternDimension; + private final Pattern patternHazmat; public HeavyVehicleGraphStorageBuilder() { motorVehicleRestrictions.addAll(Arrays.asList("motorcar", "motor_vehicle", "vehicle", "access")); @@ -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 { @@ -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; } }