Skip to content

Commit

Permalink
Add SidewalkTraversalPermissionLabeler
Browse files Browse the repository at this point in the history
activated via TransportNetworkConfig when building a network from a config JSON
  • Loading branch information
ansoncfit committed Aug 9, 2024
1 parent a96f49a commit 1f68767
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ public class TransportNetworkConfig {
*/
public Set<StreetMode> buildGridsForModes;

/**
* Specifies which "labeler" to use when setting traversal mode permissions from OSM tags. For now, only
* implemented with "sidewalk" to use the SidewalkTraversalPermissionLayer. This should eventually be cleaned up
* (specifying different labelers, using enums).
*/
public String traversalPermissionLabeler;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.conveyal.r5.labeling;


/**
* 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 SidewalkTraversalPermissionLabeler 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;foot=no"); // Note foot=no

}

}
16 changes: 14 additions & 2 deletions src/main/java/com/conveyal/r5/streets/StreetLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import com.conveyal.osmlib.OSMEntity;
import com.conveyal.osmlib.Relation;
import com.conveyal.osmlib.Way;
import com.conveyal.r5.analyst.cluster.TransportNetworkConfig;
import com.conveyal.r5.analyst.scenario.PickupWaitTimes;
import com.conveyal.r5.api.util.BikeRentalStation;
import com.conveyal.r5.api.util.ParkRideParking;
import com.conveyal.r5.common.GeometryUtils;
import com.conveyal.r5.labeling.LevelOfTrafficStressLabeler;
import com.conveyal.r5.labeling.RoadPermission;
import com.conveyal.r5.labeling.SidewalkTraversalPermissionLabeler;
import com.conveyal.r5.labeling.SpeedLabeler;
import com.conveyal.r5.labeling.StreetClass;
import com.conveyal.r5.labeling.TraversalPermissionLabeler;
Expand Down Expand Up @@ -132,8 +134,8 @@ public class StreetLayer implements Serializable, Cloneable {
public TIntObjectMap<ParkRideParking> parkRideLocationsMap;

// TODO these are only needed when building the network, should we really be keeping them here in the layer?
// We should instead have a network builder that holds references to this transient state.
// TODO don't hardwire to US
// We should instead have a network builder that holds references to this transient state. Note initial
// approach of specifying a TraversalPermissionLabeler in TransportNetworkConfig.
private transient TraversalPermissionLabeler permissionLabeler = new USTraversalPermissionLabeler();
private transient LevelOfTrafficStressLabeler stressLabeler = new LevelOfTrafficStressLabeler();
private transient TypeOfEdgeLabeler typeOfEdgeLabeler = new TypeOfEdgeLabeler();
Expand Down Expand Up @@ -209,6 +211,16 @@ public StreetLayer() {
speedLabeler = new SpeedLabeler(SpeedConfig.defaultConfig());
}

public StreetLayer(TransportNetworkConfig config) {
this();
if (config != null && config.traversalPermissionLabeler != null) {
// TODO cleaner mapping
if ("sidewalk".equals(config.traversalPermissionLabeler)) {
permissionLabeler = new SidewalkTraversalPermissionLabeler();
}
}
}

/** Load street layer from an OSM-lib OSM DB */
public void loadFromOsm(OSM osm) {
loadFromOsm(osm, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ private TransportNetwork buildNetworkFromConfig (TransportNetworkConfig config)

TransportNetwork network = new TransportNetwork();

network.streetLayer = new StreetLayer();
network.streetLayer = new StreetLayer(config);

network.streetLayer.loadFromOsm(osmCache.get(config.osmId));

network.streetLayer.parentNetwork = network;
Expand Down

0 comments on commit 1f68767

Please sign in to comment.