From 55944d9a8126a845b002b5e9e80ce88e2db72e0d Mon Sep 17 00:00:00 2001 From: ansons Date: Fri, 3 Jan 2025 15:54:53 -0500 Subject: [PATCH] Add NoMotorwayTraversalPermissionLabeler --- .../NoMotorwayTraversalPermissionLabeler.java | 31 +++++++++++++++++++ .../com/conveyal/r5/streets/StreetLayer.java | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/com/conveyal/r5/labeling/NoMotorwayTraversalPermissionLabeler.java diff --git a/src/main/java/com/conveyal/r5/labeling/NoMotorwayTraversalPermissionLabeler.java b/src/main/java/com/conveyal/r5/labeling/NoMotorwayTraversalPermissionLabeler.java new file mode 100644 index 000000000..8e79f99e9 --- /dev/null +++ b/src/main/java/com/conveyal/r5/labeling/NoMotorwayTraversalPermissionLabeler.java @@ -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; + } + +} diff --git a/src/main/java/com/conveyal/r5/streets/StreetLayer.java b/src/main/java/com/conveyal/r5/streets/StreetLayer.java index 4e31481ee..4b3ade468 100644 --- a/src/main/java/com/conveyal/r5/streets/StreetLayer.java +++ b/src/main/java/com/conveyal/r5/streets/StreetLayer.java @@ -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; @@ -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