Skip to content

Commit 4bd0f6e

Browse files
authored
Merge pull request #945 from conveyal/config-save-shapes
Add network config option to save GTFS shapes
2 parents f2a9d33 + 3b26f82 commit 4bd0f6e

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/main/java/com/conveyal/r5/analyst/cluster/TransportNetworkConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ public class TransportNetworkConfig {
5757
*/
5858
public String traversalPermissionLabeler;
5959

60+
/** Whether to save detailed trip shapes from GTFS (e.g., for Conveyal Taui sites or the Network Viewer). If false,
61+
* straight line segments between stops will be used in visualizations.
62+
*/
63+
public boolean saveShapes;
64+
6065
}

src/main/java/com/conveyal/r5/transit/TransitLayer.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.conveyal.gtfs.model.Stop;
1111
import com.conveyal.gtfs.model.StopTime;
1212
import com.conveyal.gtfs.model.Trip;
13+
import com.conveyal.r5.analyst.cluster.TransportNetworkConfig;
1314
import com.conveyal.r5.api.util.TransitModes;
1415
import com.conveyal.r5.common.GeometryUtils;
1516
import com.conveyal.r5.streets.EdgeStore;
@@ -66,8 +67,6 @@ public class TransitLayer implements Serializable, Cloneable {
6667
/** Maximum distance to record in distance tables, in meters. */
6768
public static final int WALK_DISTANCE_LIMIT_METERS = 2000;
6869

69-
public static final boolean SAVE_SHAPES = false;
70-
7170
/**
7271
* Distance limit for transfers, meters. Set to 1km which is slightly above OTP's 600m (which was specified as
7372
* 1 m/s with 600s max time, which is actually somewhat less than 600m due to extra costs due to steps etc.
@@ -166,6 +165,11 @@ public class TransitLayer implements Serializable, Cloneable {
166165

167166
public Map<String, Fare> fares;
168167

168+
/** Whether to save detailed trip shapes from GTFS (e.g., for Conveyal Taui sites). Unless the default false
169+
* value is overwritten by a transportNetworkConfig file, straight line segments between stops will be used in
170+
* visualiations.*/
171+
public boolean saveShapes = false;
172+
169173
/** Map from feed ID to feed CRC32 to ensure that we can't apply scenarios to the wrong feeds */
170174
public Map<String, Long> feedChecksums = new HashMap<>();
171175

@@ -179,6 +183,17 @@ public class TransitLayer implements Serializable, Cloneable {
179183
*/
180184
public String scenarioId;
181185

186+
public TransitLayer () {
187+
// Default constructor. Does not exist implicitly when one-arg constructor is present.
188+
// Necessary to ensure fields with initializer expressions are initialized upon deserialization.
189+
}
190+
191+
public TransitLayer (TransportNetworkConfig config) {
192+
if (config != null) {
193+
saveShapes = config.saveShapes;
194+
}
195+
}
196+
182197
/**
183198
* Load a GTFS feed with full load level. The feed is not closed after being loaded.
184199
* TODO eliminate "load levels"
@@ -307,7 +322,7 @@ public void loadFromGtfs (GTFSFeed gtfs, LoadLevel level) throws DuplicateFeedEx
307322

308323
tripPattern.routeIndex = routeIndexForRoute.get(trip.route_id);
309324

310-
if (trip.shape_id != null && SAVE_SHAPES) {
325+
if (trip.shape_id != null && saveShapes) {
311326
Shape shape = gtfs.getShape(trip.shape_id);
312327
if (shape == null) LOG.warn("Shape {} for trip {} was missing", trip.shape_id, trip.trip_id);
313328
else {

src/main/java/com/conveyal/r5/transit/TransportNetwork.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static TransportNetwork fromInputs (OSM osm, Stream<GTFSFeed> gtfsFeeds,
166166
streetLayer.indexStreets();
167167

168168
// Load transit data
169-
TransitLayer transitLayer = new TransitLayer();
169+
TransitLayer transitLayer = new TransitLayer(config);
170170
gtfsFeeds.forEach(gtfsFeed -> {
171171
transitLayer.loadFromGtfs(gtfsFeed);
172172
// Is there a reason we can't push this close call down into the loader method? Maybe exception handling?

src/main/java/com/conveyal/r5/transit/TransportNetworkCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private TransportNetwork buildNetworkFromConfig (TransportNetworkConfig config)
254254
network.streetLayer.parentNetwork = network;
255255
network.streetLayer.indexStreets();
256256

257-
network.transitLayer = new TransitLayer();
257+
network.transitLayer = new TransitLayer(config);
258258

259259
config.gtfsIds.stream()
260260
.map(gtfsCache::get)

0 commit comments

Comments
 (0)