From 371ee42bca87baf90c8ce75ec36f8da7f6e319e8 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Fri, 16 Aug 2024 10:38:36 -0400
Subject: [PATCH] feat(OsmModule): Add build option to prevent ped routing on
roads.
---
docs/BuildConfiguration.md | 10 ++++++++++
.../module/configure/GraphBuilderModules.java | 1 +
.../graph_builder/module/osm/OsmModule.java | 7 ++++++-
.../graph_builder/module/osm/OsmModuleBuilder.java | 9 ++++++++-
.../module/osm/parameters/OsmProcessingParameters.java | 3 ++-
.../opentripplanner/standalone/config/BuildConfig.java | 10 ++++++++++
6 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/docs/BuildConfiguration.md b/docs/BuildConfiguration.md
index 7d2d90ea41b..6a38b5466ef 100644
--- a/docs/BuildConfiguration.md
+++ b/docs/BuildConfiguration.md
@@ -37,6 +37,7 @@ Sections follow that describe particular settings in more depth.
| [osmCacheDataInMem](#osmCacheDataInMem) | `boolean` | If OSM data should be cached in memory during processing. | *Optional* | `false` | 2.0 |
| [osmNaming](#osmNaming) | `enum` | A custom OSM namer to use. | *Optional* | `"default"` | 1.5 |
| platformEntriesLinking | `boolean` | Link unconnected entries to public transport platforms. | *Optional* | `false` | 2.0 |
+| [preventWalkingOnRoads](#preventWalkingOnRoads) | `boolean` | Determines whether to prevent pedestrian routing on roads or not. | *Optional* | `false` | 2.5 |
| [readCachedElevations](#readCachedElevations) | `boolean` | Whether to read cached elevation data. | *Optional* | `true` | 2.0 |
| staticBikeParkAndRide | `boolean` | Whether we should create bike P+R stations from OSM data. | *Optional* | `false` | 1.5 |
| staticParkAndRide | `boolean` | Whether we should create car P+R stations from OSM data. | *Optional* | `true` | 1.5 |
@@ -528,6 +529,15 @@ data, and to `false` to read the stream from the source each time.
A custom OSM namer to use.
+
preventWalkingOnRoads
+
+**Since version:** `2.5` ∙ **Type:** `boolean` ∙ **Cardinality:** `Optional` ∙ **Default value:** `false`
+**Path:** /
+
+Determines whether to prevent pedestrian routing on roads or not.
+
+True to prevent pedestrian routing on roads.
+
readCachedElevations
**Since version:** `2.0` ∙ **Type:** `boolean` ∙ **Cardinality:** `Optional` ∙ **Default value:** `true`
diff --git a/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java b/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java
index 10d3a997579..e0c1bd26914 100644
--- a/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java
+++ b/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java
@@ -85,6 +85,7 @@ static OsmModule provideOpenStreetMapModule(
.withBoardingAreaRefTags(config.boardingLocationTags)
.withIssueStore(issueStore)
.withStreetLimitationParameters(streetLimitationParameters)
+ .withPreventWalkingOnRoads(config.preventWalkingOnRoads)
.build();
}
diff --git a/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java b/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java
index 6fe3caf468e..65c12d5aa20 100644
--- a/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java
+++ b/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java
@@ -16,6 +16,7 @@
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.ext.mobilityprofile.MobilityProfileParser;
+import org.opentripplanner.ext.mobilityprofile.MobilityProfileRouting;
import org.opentripplanner.framework.geometry.GeometryUtils;
import org.opentripplanner.framework.geometry.SphericalDistanceLibrary;
import org.opentripplanner.framework.i18n.I18NString;
@@ -569,13 +570,17 @@ private StreetEdge getEdgeForStreet(
LOG.warn("Unable to extract OSM nodes for way {} {}, {}=>{}", name, wayId, startId, endId);
}
+ StreetTraversalPermission perms = params.preventWalkingOnRoads()
+ ? MobilityProfileRouting.adjustPedestrianPermissions(way, permissions)
+ : permissions;
+
StreetEdgeBuilder> seb = new StreetEdgeBuilder<>()
.withFromVertex(startEndpoint)
.withToVertex(endEndpoint)
.withGeometry(geometry)
.withName(name)
.withMeterLength(length)
- .withPermission(permissions)
+ .withPermission(perms)
.withBack(back)
.withCarSpeed(carSpeed)
.withLink(way.isLink())
diff --git a/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModuleBuilder.java b/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModuleBuilder.java
index f0a40fa678f..eb19e491430 100644
--- a/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModuleBuilder.java
+++ b/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModuleBuilder.java
@@ -26,6 +26,7 @@ public class OsmModuleBuilder {
private boolean staticBikeParkAndRide = false;
private int maxAreaNodes;
private StreetLimitationParameters streetLimitationParameters = new StreetLimitationParameters();
+ private boolean preventWalkingOnRoads;
OsmModuleBuilder(Collection providers, Graph graph) {
this.providers = providers;
@@ -77,6 +78,11 @@ public OsmModuleBuilder withStreetLimitationParameters(StreetLimitationParameter
return this;
}
+ public OsmModuleBuilder withPreventWalkingOnRoads(boolean value) {
+ this.preventWalkingOnRoads = value;
+ return this;
+ }
+
public OsmModule build() {
return new OsmModule(
providers,
@@ -90,7 +96,8 @@ public OsmModule build() {
areaVisibility,
platformEntriesLinking,
staticParkAndRide,
- staticBikeParkAndRide
+ staticBikeParkAndRide,
+ preventWalkingOnRoads
)
);
}
diff --git a/src/main/java/org/opentripplanner/graph_builder/module/osm/parameters/OsmProcessingParameters.java b/src/main/java/org/opentripplanner/graph_builder/module/osm/parameters/OsmProcessingParameters.java
index 52bf8d65314..38229fc79ff 100644
--- a/src/main/java/org/opentripplanner/graph_builder/module/osm/parameters/OsmProcessingParameters.java
+++ b/src/main/java/org/opentripplanner/graph_builder/module/osm/parameters/OsmProcessingParameters.java
@@ -21,7 +21,8 @@ public record OsmProcessingParameters(
boolean areaVisibility,
boolean platformEntriesLinking,
boolean staticParkAndRide,
- boolean staticBikeParkAndRide
+ boolean staticBikeParkAndRide,
+ boolean preventWalkingOnRoads
) {
public OsmProcessingParameters {
boardingAreaRefTags = Set.copyOf(Objects.requireNonNull(boardingAreaRefTags));
diff --git a/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java b/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java
index a3c6f313799..a7e7afc3b9b 100644
--- a/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java
+++ b/src/main/java/org/opentripplanner/standalone/config/BuildConfig.java
@@ -185,6 +185,8 @@ public class BuildConfig implements OtpDataStoreConfig {
public final URI stopConsolidation;
+ public final boolean preventWalkingOnRoads;
+
/**
* Set all parameters from the given Jackson JSON tree, applying defaults. Supplying
* MissingNode.getInstance() will cause all the defaults to be applied. This could be done
@@ -612,6 +614,14 @@ that we support remote input files (cloud storage or arbitrary URLs) not all dat
)
.asUri(null);
+ preventWalkingOnRoads =
+ root
+ .of("preventWalkingOnRoads")
+ .since(V2_5)
+ .summary("Determines whether to prevent pedestrian routing on roads or not.")
+ .description("True to prevent pedestrian routing on roads.")
+ .asBoolean(false);
+
osmDefaults = OsmConfig.mapOsmDefaults(root, "osmDefaults");
osm = OsmConfig.mapOsmConfig(root, "osm", osmDefaults);
demDefaults = DemConfig.mapDemDefaultsConfig(root, "demDefaults");