Skip to content

Commit

Permalink
Add NoMotorwayTraversalPermissionLabeler
Browse files Browse the repository at this point in the history
  • Loading branch information
ansoncfit committed Jan 3, 2025
1 parent 5648f0b commit 55944d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.conveyal.r5.labeling;

import com.conveyal.osmlib.Way;
import com.conveyal.r5.streets.EdgeStore;

/**
* Traversal permission labeler that restricts walking on most driving ways (useful for networks with complete
* sidewalks). Also includes permissions for the United States (see USTraversalPermissionLabeler).
*/
public class NoMotorwayTraversalPermissionLabeler extends TraversalPermissionLabeler {
static {
addPermissions("pedestrian", "bicycle=yes");
addPermissions("bridleway", "bicycle=yes;foot=yes"); //horse=yes but we don't support horse
addPermissions("cycleway", "bicycle=yes;foot=yes");
addPermissions("trunk|primary|secondary|tertiary|unclassified|residential|living_street|road|service|track",
"access=yes");
}

@Override
public RoadPermission getPermissions(Way way) {
RoadPermission rp = super.getPermissions(way);
if (way.tagIsTrue("motorway")) {
rp.forward.remove(EdgeStore.EdgeFlag.ALLOWS_CAR);
rp.forward.remove(EdgeStore.EdgeFlag.NO_THRU_TRAFFIC_CAR);
rp.backward.remove(EdgeStore.EdgeFlag.ALLOWS_CAR);
rp.backward.remove(EdgeStore.EdgeFlag.NO_THRU_TRAFFIC_CAR);
}
return rp;
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/conveyal/r5/streets/StreetLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.conveyal.r5.api.util.ParkRideParking;
import com.conveyal.r5.common.GeometryUtils;
import com.conveyal.r5.labeling.LevelOfTrafficStressLabeler;
import com.conveyal.r5.labeling.NoMotorwayTraversalPermissionLabeler;
import com.conveyal.r5.labeling.RoadPermission;
import com.conveyal.r5.labeling.SidewalkTraversalPermissionLabeler;
import com.conveyal.r5.labeling.SpeedLabeler;
Expand Down Expand Up @@ -217,6 +218,7 @@ public StreetLayer(TransportNetworkConfig config) {
if (config != null) {
permissionLabeler = switch (config.traversalPermissionLabeler) {
case "sidewalk" -> new SidewalkTraversalPermissionLabeler();
case "noMotorway" -> new NoMotorwayTraversalPermissionLabeler();
case null -> new USTraversalPermissionLabeler();
default -> throw new IllegalArgumentException(
"Unknown traversal permission labeler: " + config.traversalPermissionLabeler
Expand Down

0 comments on commit 55944d9

Please sign in to comment.