Skip to content

Commit

Permalink
Add network config option to save GTFS shapes
Browse files Browse the repository at this point in the history
Fixes #751
  • Loading branch information
ansoncfit committed Oct 10, 2024
1 parent e5a9a26 commit 25f6232
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public class TransportNetworkConfig {
*/
public String traversalPermissionLabeler;

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

}
16 changes: 13 additions & 3 deletions src/main/java/com/conveyal/r5/transit/TransitLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.conveyal.gtfs.model.Stop;
import com.conveyal.gtfs.model.StopTime;
import com.conveyal.gtfs.model.Trip;
import com.conveyal.r5.analyst.cluster.TransportNetworkConfig;
import com.conveyal.r5.api.util.TransitModes;
import com.conveyal.r5.common.GeometryUtils;
import com.conveyal.r5.streets.EdgeStore;
Expand Down Expand Up @@ -66,8 +67,6 @@ public class TransitLayer implements Serializable, Cloneable {
/** Maximum distance to record in distance tables, in meters. */
public static final int WALK_DISTANCE_LIMIT_METERS = 2000;

public static final boolean SAVE_SHAPES = false;

/**
* Distance limit for transfers, meters. Set to 1km which is slightly above OTP's 600m (which was specified as
* 1 m/s with 600s max time, which is actually somewhat less than 600m due to extra costs due to steps etc.
Expand Down Expand Up @@ -166,6 +165,11 @@ public class TransitLayer implements Serializable, Cloneable {

public Map<String, Fare> fares;

/** Whether to save detailed trip shapes from GTFS (e.g., for Conveyal Taui sites). Unless the default false
* value is overwritten by a transportNetworkConfig file, straight line segments between stops will be used in
* visualiations.*/
public boolean saveShapes = false;

/** Map from feed ID to feed CRC32 to ensure that we can't apply scenarios to the wrong feeds */
public Map<String, Long> feedChecksums = new HashMap<>();

Expand All @@ -179,6 +183,12 @@ public class TransitLayer implements Serializable, Cloneable {
*/
public String scenarioId;

public TransitLayer (TransportNetworkConfig config) {
if (config != null) {
saveShapes = config.saveShapes;
}
}

/**
* Load a GTFS feed with full load level. The feed is not closed after being loaded.
* TODO eliminate "load levels"
Expand Down Expand Up @@ -307,7 +317,7 @@ public void loadFromGtfs (GTFSFeed gtfs, LoadLevel level) throws DuplicateFeedEx

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

if (trip.shape_id != null && SAVE_SHAPES) {
if (trip.shape_id != null && saveShapes) {
Shape shape = gtfs.getShape(trip.shape_id);
if (shape == null) LOG.warn("Shape {} for trip {} was missing", trip.shape_id, trip.trip_id);
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static TransportNetwork fromInputs (OSM osm, Stream<GTFSFeed> gtfsFeeds,
streetLayer.indexStreets();

// Load transit data
TransitLayer transitLayer = new TransitLayer();
TransitLayer transitLayer = new TransitLayer(config);
gtfsFeeds.forEach(gtfsFeed -> {
transitLayer.loadFromGtfs(gtfsFeed);
// Is there a reason we can't push this close call down into the loader method? Maybe exception handling?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private TransportNetwork buildNetworkFromConfig (TransportNetworkConfig config)
network.streetLayer.parentNetwork = network;
network.streetLayer.indexStreets();

network.transitLayer = new TransitLayer();
network.transitLayer = new TransitLayer(config);

config.gtfsIds.stream()
.map(gtfsCache::get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FrequencyRandomOffsetsTest {
@Test
public void testPhasing () {
// make a fake transit layer
TransitLayer layer = new TransitLayer();
TransitLayer layer = new TransitLayer(null);
layer.hasFrequencies = true;
layer.hasSchedules = false;

Expand Down Expand Up @@ -86,7 +86,7 @@ public void testPhasing () {
@Test
public void testPhasingAtLastStop () {
// make a fake transit layer
TransitLayer layer = new TransitLayer();
TransitLayer layer = new TransitLayer(null);
layer.hasFrequencies = true;
layer.hasSchedules = false;

Expand Down

0 comments on commit 25f6232

Please sign in to comment.