From 51213c07230c1c391c197fa64ca776bd19ba2558 Mon Sep 17 00:00:00 2001 From: ratrun Date: Fri, 14 Jun 2024 16:00:22 +0200 Subject: [PATCH] Slightly increase bicycle priority classification on "good" highway=track --- .../util/parsers/BikeCommonPriorityParser.java | 6 +++++- .../util/parsers/MountainBikePriorityParser.java | 5 +++-- .../util/parsers/RacingBikePriorityParser.java | 5 +++-- .../routing/util/parsers/BikeTagParserTest.java | 12 ++++++++++++ .../util/parsers/MountainBikeTagParserTest.java | 6 +++--- .../util/parsers/RacingBikeTagParserTest.java | 15 ++++++++++++++- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonPriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonPriorityParser.java index d20fcd5e15b..0ead9345b63 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonPriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonPriorityParser.java @@ -36,6 +36,7 @@ public abstract class BikeCommonPriorityParser implements TagParser { int avoidSpeedLimit; EnumEncodedValue bikeRouteEnc; Map routeMap = new HashMap<>(); + protected final Set goodSurface = new HashSet<>(List.of("paved", "asphalt", "concrete")); // This is the specific bicycle class private String classBicycleKey; @@ -153,8 +154,11 @@ private PriorityCode convertClassValueToPriority(String tagvalue) { */ void collect(ReaderWay way, double wayTypeSpeed, TreeMap weightToPrioMap) { String highway = way.getTag("highway"); + boolean isTracTypeGrade1 = way.getTag("tracktype", "").equals("grade1"); + boolean isGoodSurface = goodSurface.contains(way.getTag("surface","")); if (isDesignated(way)) { - if ("path".equals(highway)) + if ("path".equals(highway) || + ("track".equals(highway) && (isTracTypeGrade1 || isGoodSurface ))) weightToPrioMap.put(100d, VERY_NICE); else weightToPrioMap.put(100d, PREFER); diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java index f124c7d4d3c..bdbc77cd69e 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java @@ -45,8 +45,9 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap w String highway = way.getTag("highway"); if ("track".equals(highway)) { String trackType = way.getTag("tracktype"); - if ("grade1".equals(trackType)) - weightToPrioMap.put(50d, UNCHANGED); + boolean isGoodSurface = goodSurface.contains(way.getTag("surface","")); + if ("grade1".equals(trackType) || isGoodSurface) + weightToPrioMap.put(50d, SLIGHT_PREFER); else if (trackType == null) weightToPrioMap.put(90d, PREFER); else if (trackType.startsWith("grade")) diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java index 9ead7ff7ea3..8a46bae141f 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java @@ -55,9 +55,10 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap w if ("service".equals(highway) || "residential".equals(highway)) { weightToPrioMap.put(40d, SLIGHT_AVOID); } else if ("track".equals(highway)) { + boolean isGoodSurface = goodSurface.contains(way.getTag("surface","")); String trackType = way.getTag("tracktype"); - if ("grade1".equals(trackType)) - weightToPrioMap.put(110d, PREFER); + if ("grade1".equals(trackType) || isGoodSurface ) + weightToPrioMap.put(110d, VERY_NICE); else if (trackType == null || trackType.startsWith("grade")) weightToPrioMap.put(110d, AVOID_MORE); } diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java index 1799cb315ca..ebc608d9a88 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java @@ -162,6 +162,18 @@ public void testSpeedAndPriority() { way.setTag("surface", "paved"); assertPriorityAndSpeed(PREFER, 18, way); + way.clearTags(); + way.setTag("highway", "track"); + way.setTag("bicycle", "designated"); + way.setTag("segregated","no"); + assertPriorityAndSpeed(PREFER, 12, way); + way.setTag("surface", "asphalt"); + assertPriorityAndSpeed(VERY_NICE, cyclewaySpeed, way); + way.setTag("tracktype","grade1"); + assertPriorityAndSpeed(VERY_NICE, cyclewaySpeed, way); + way.removeTag("surface"); + assertPriorityAndSpeed(VERY_NICE, cyclewaySpeed, way); + way.clearTags(); way.setTag("highway", "path"); assertPriorityAndSpeed(SLIGHT_AVOID, PUSHING_SECTION_SPEED, way); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java index c978340b173..6452cfb7e1c 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java @@ -78,8 +78,6 @@ public void testSpeedAndPriority() { way.setTag("highway", "track"); assertPriorityAndSpeed(PREFER, 18, way); - // test speed for allowed pushing section types - way.setTag("highway", "track"); way.setTag("bicycle", "yes"); assertPriorityAndSpeed(PREFER, 18, way); @@ -87,9 +85,11 @@ public void testSpeedAndPriority() { way.setTag("bicycle", "yes"); way.setTag("tracktype", "grade3"); assertPriorityAndSpeed(VERY_NICE, 12, way); + way.setTag("tracktype", "grade1"); + assertPriorityAndSpeed(SLIGHT_PREFER, 18, way); way.setTag("surface", "paved"); - assertPriorityAndSpeed(VERY_NICE, 18, way); + assertPriorityAndSpeed(SLIGHT_PREFER, 18, way); way.clearTags(); way.setTag("highway", "path"); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java index d61357530d2..5a1dbc24203 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java @@ -96,6 +96,19 @@ public void testService() { assertPriorityAndSpeed(SLIGHT_AVOID, 4, way); } + @Test + public void testTrack() { + ReaderWay way = new ReaderWay(1); + way.setTag("highway", "track"); + way.setTag("bicycle", "designated"); + way.setTag("segregated","no"); + assertPriorityAndSpeed(AVOID_MORE, 2, way); + way.setTag("surface", "asphalt"); + assertPriorityAndSpeed(VERY_NICE, 20, way); + way.setTag("tracktype","grade1"); + assertPriorityAndSpeed(VERY_NICE, 20, way); + } + @Test @Override public void testSacScale() { @@ -208,7 +221,7 @@ public void testHandleWayTagsInfluencedByRelation() { // Now we assume bicycle=yes, and paved osmWay.setTag("tracktype", "grade1"); - assertPriorityAndSpeed(PREFER, 20, osmWay, osmRel); + assertPriorityAndSpeed(VERY_NICE, 20, osmWay, osmRel); // Now we assume bicycle=yes, and unpaved as part of a cycle relation osmWay.setTag("tracktype", "grade2");