diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/AbstractAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/AbstractAccessParser.java index 18a698e7ffc..286508ed328 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/AbstractAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/AbstractAccessParser.java @@ -23,6 +23,7 @@ public abstract class AbstractAccessParser implements TagParser { protected final Set barriers = new HashSet<>(5); protected final BooleanEncodedValue accessEnc; private boolean blockFords = true; + private TransportationMode transportationMode; protected AbstractAccessParser(BooleanEncodedValue accessEnc, TransportationMode transportationMode) { this.accessEnc = accessEnc; @@ -35,6 +36,7 @@ protected AbstractAccessParser(BooleanEncodedValue accessEnc, TransportationMode restrictedValues.add("permit"); restrictionKeys.addAll(OSMRoadAccessParser.toOSMRestrictions(transportationMode)); + this.transportationMode = transportationMode; } public boolean isBlockFords() { @@ -74,13 +76,29 @@ public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way public abstract void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way); + private String getVehicleAccessTag(){ + if (this.transportationMode.isMotorVehicle()) + return "motorcar"; + switch (this.transportationMode) { + case FOOT: + return "foot"; + case BIKE: + return "bicycle"; + case VEHICLE: + return "vehicle"; + case OTHER: + default: + throw new IllegalArgumentException("Unknown transportationMode"); + } + } + /** * @return true if the given OSM node blocks access for the specified restrictions, false otherwise */ public boolean isBarrier(ReaderNode node) { // note that this method will be only called for certain nodes as defined by OSMReader! String firstValue = node.getFirstValue(restrictionKeys); - if (restrictedValues.contains(firstValue) || node.hasTag("locked", "yes")) + if (restrictedValues.contains(firstValue) || (node.hasTag("locked", "yes") && !node.hasTag(getVehicleAccessTag(), intendedValues))) return true; else if (intendedValues.contains(firstValue)) return false; diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java b/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java index 3f379d7e2e6..619f534f4bb 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java @@ -399,6 +399,8 @@ public void testLockedGate() { node.setTag("barrier", "gate"); node.setTag("locked", "yes"); assertTrue(accessParser.isBarrier(node)); + node.setTag("bicycle", "yes"); + assertFalse(accessParser.isBarrier(node)); } @Test diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java index 7dd4def46e9..1787db97d8d 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java @@ -443,12 +443,16 @@ public void testBarrierAccess() { node = new ReaderNode(1, -1, -1); node.setTag("barrier", "gate"); node.setTag("access", "no"); + assertTrue(accessParser.isBarrier(node)); node.setTag("foot", "yes"); - // no barrier! + assertFalse(accessParser.isBarrier(node)); + node.setTag("locked", "yes"); + // no barrier for foot=yes! assertFalse(accessParser.isBarrier(node)); + node.clearTags(); + node.setTag("barrier", "yes"); node.setTag("locked", "yes"); - // barrier! assertTrue(accessParser.isBarrier(node)); node.clearTags();