Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ratrun committed Apr 21, 2024
1 parent 1c2f22e commit cf67c11
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class AbstractAccessParser implements TagParser {
protected final Set<String> barriers = new HashSet<>(5);
protected final BooleanEncodedValue accessEnc;
private boolean blockFords = true;
private TransportationMode transportationMode;

protected AbstractAccessParser(BooleanEncodedValue accessEnc, TransportationMode transportationMode) {
this.accessEnc = accessEnc;
Expand All @@ -35,6 +36,7 @@ protected AbstractAccessParser(BooleanEncodedValue accessEnc, TransportationMode
restrictedValues.add("permit");

restrictionKeys.addAll(OSMRoadAccessParser.toOSMRestrictions(transportationMode));
this.transportationMode = transportationMode;
}

public boolean isBlockFords() {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit cf67c11

Please sign in to comment.