Repository: graphhopper/graphhopper
Pull request #1568 (2019-03-07 14:09:46)

Ferry bicycle or foot designated
fixed FootFlagEncoder and BikeCommonFlagEncoder to acceptWay when route=ferry and foot/bicycle is contained in intendedValue (yes, designated, official, permissive)

This is my first contribution to graphhopper, I'm open for feedback :)

see also https://github.com/graphhopper/graphhopper/issues/1562

karussell: This looks good thanks! Also got the CLA, so this should be fine to merge :+1:  (will also consider it for 0.12)

Patch:
diff --git a/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java b/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
index f989b7ba9..06bc1df0b 100644
--- a/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
+++ b/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
@@ -233,7 +233,7 @@ abstract public class BikeCommonFlagEncoder extends AbstractFlagEncoder {
             if (way.hasTag("route", ferries)) {
                 // if bike is NOT explicitly tagged allow bike but only if foot is not specified
                 String bikeTag = way.getTag("bicycle");
-                if (bikeTag == null && !way.hasTag("foot") || "yes".equals(bikeTag))
+                if (bikeTag == null && !way.hasTag("foot") || intendedValues.contains(bikeTag))
                     accept = EncodingManager.Access.FERRY;
             }
 
diff --git a/core/src/main/java/com/graphhopper/routing/util/FootFlagEncoder.java b/core/src/main/java/com/graphhopper/routing/util/FootFlagEncoder.java
index d212e2fc0..e41a0d0c6 100644
--- a/core/src/main/java/com/graphhopper/routing/util/FootFlagEncoder.java
+++ b/core/src/main/java/com/graphhopper/routing/util/FootFlagEncoder.java
@@ -205,7 +205,7 @@ public class FootFlagEncoder extends AbstractFlagEncoder {
 
             if (way.hasTag("route", ferries)) {
                 String footTag = way.getTag("foot");
-                if (footTag == null || "yes".equals(footTag))
+                if (footTag == null || intendedValues.contains(footTag))
                     acceptPotentially = EncodingManager.Access.FERRY;
             }
 


Test patch:
diff --git a/core/src/test/java/com/graphhopper/routing/util/AbstractBikeFlagEncoderTester.java b/core/src/test/java/com/graphhopper/routing/util/AbstractBikeFlagEncoderTester.java
index 77525f213..ee1fae741 100644
--- a/core/src/test/java/com/graphhopper/routing/util/AbstractBikeFlagEncoderTester.java
+++ b/core/src/test/java/com/graphhopper/routing/util/AbstractBikeFlagEncoderTester.java
@@ -171,16 +171,7 @@ public abstract class AbstractBikeFlagEncoderTester {
         way.setTag("bicycle", "dismount");
         assertTrue(encoder.getAccess(way).isWay());
 
-        way.clearTags();
-        way.setTag("route", "ferry");
-        assertTrue(encoder.getAccess(way).isFerry());
-        way.setTag("bicycle", "no");
-        assertTrue(encoder.getAccess(way).canSkip());
-
-        way.clearTags();
-        way.setTag("route", "ferry");
-        way.setTag("foot", "yes");
-        assertTrue(encoder.getAccess(way).canSkip());
+        
 
         way.clearTags();
         way.setTag("highway", "cycleway");
@@ -486,4 +477,55 @@ public abstract class AbstractBikeFlagEncoderTester {
         // no barrier!
         assertTrue(encoder.handleNodeTags(node) == 0);
     }
+
+    @Test
+    public void testFerries(){
+        ReaderWay way = new ReaderWay(1);
+
+        way.clearTags();
+        way.setTag("route", "ferry");
+        assertTrue(encoder.getAccess(way).isFerry());
+        way.setTag("bicycle", "no");
+        assertFalse(encoder.getAccess(way).isFerry());
+
+        way.clearTags();
+        way.setTag("route", "ferry");
+        way.setTag("foot", "yes");
+        assertFalse(encoder.getAccess(way).isFerry());
+
+        // #1122
+        way.clearTags();
+        way.setTag("route", "ferry");
+        way.setTag("bicycle", "yes");
+        way.setTag("access", "private");
+        assertTrue(encoder.getAccess(way).canSkip());
+
+        // #1562, test if ferry route with bicycle
+        way.clearTags();
+        way.setTag("route", "ferry");
+        way.setTag("bicycle", "designated");
+        assertTrue(encoder.getAccess(way).isFerry());
+
+        way.setTag("bicycle", "official");
+        assertTrue(encoder.getAccess(way).isFerry());
+
+        way.setTag("bicycle", "permissive");
+        assertTrue(encoder.getAccess(way).isFerry());
+
+        way.setTag("foot", "yes");
+        assertTrue(encoder.getAccess(way).isFerry());
+
+        way.setTag("bicycle", "no");
+        assertTrue(encoder.getAccess(way).canSkip());
+
+        way.setTag("bicycle", "designated");
+        way.setTag("access", "private");
+        assertTrue(encoder.getAccess(way).canSkip());
+
+        // test if when foot is set is invalid
+        way.clearTags();
+        way.setTag("route", "ferry");
+        way.setTag("foot", "yes");
+        assertTrue(encoder.getAccess(way).canSkip());
+    }
 }
diff --git a/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java b/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
index 82594df9b..071c49626 100644
--- a/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
@@ -316,13 +316,6 @@ public class BikeFlagEncoderTest extends AbstractBikeFlagEncoderTester {
         way.setTag("bicycle", "yes");
         way.setTag("access", "no");
         assertTrue(encoder.getAccess(way).isWay());
-
-        // #1122
-        way.clearTags();
-        way.setTag("route", "ferry");
-        way.setTag("bicycle", "yes");
-        way.setTag("access", "private");
-        assertTrue(encoder.getAccess(way).canSkip());
     }
 
     @Test
diff --git a/core/src/test/java/com/graphhopper/routing/util/FootFlagEncoderTest.java b/core/src/test/java/com/graphhopper/routing/util/FootFlagEncoderTest.java
index 57c4a45b1..91f18ba95 100644
--- a/core/src/test/java/com/graphhopper/routing/util/FootFlagEncoderTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/FootFlagEncoderTest.java
@@ -190,6 +190,28 @@ public class FootFlagEncoderTest {
         way.setTag("foot", "no");
         assertTrue(footEncoder.getAccess(way).canSkip());
 
+        // #1562, test if ferry route with foot
+        way.clearTags();
+        way.setTag("route", "ferry");
+        way.setTag("foot", "yes");
+        assertTrue(footEncoder.getAccess(way).isFerry());
+
+        way.setTag("foot", "designated");
+        assertTrue(footEncoder.getAccess(way).isFerry());
+
+        way.setTag("foot", "official");
+        assertTrue(footEncoder.getAccess(way).isFerry());
+
+        way.setTag("foot", "permissive");
+        assertTrue(footEncoder.getAccess(way).isFerry());
+
+        way.setTag("foot", "no");
+        assertTrue(footEncoder.getAccess(way).canSkip());
+
+        way.setTag("foot", "designated");
+        way.setTag("access", "private");
+        assertTrue(footEncoder.getAccess(way).canSkip());
+
         DateFormat simpleDateFormat = Helper.createFormatter("yyyy MMM dd");
 
         way.clearTags();