Skip to content

Commit e5ae1c5

Browse files
committed
tolerate and count patterns with no gtfs
these should be the ones created by other modification in the scenario. also factor out long reference chain as final List variable.
1 parent e294e80 commit e5ae1c5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Diff for: src/main/java/com/conveyal/r5/analyst/scenario/SelectLink.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ public class SelectLink extends Modification {
5050

5151
private int nPatternsWithoutShapes = 0;
5252

53+
private int nPatternsWithoutGtfs = 0;
54+
5355
@Override
5456
public boolean resolve(TransportNetwork network) {
5557
// Convert the incoming description of the selected link area to a Geometry for computing intersections.
5658
boxPolygon = polygonForEnvelope(envelopeForCircle(lon, lat, radiusMeters));
5759
// Iterate over all TripPatterns in the TransitLayer and ensure that we can associate a feed with each one.
5860
// These feeds must have been previously supplied with the injectGtfs() method. The feed IDs recorded in the
5961
// TripPatterns are not bundle-scoped. Check that a feed with a correctly de-scoped ID was supplied for every
60-
// TripPattern in this TransitLayer.
62+
// TripPattern in this TransitLayer. Note that this only applies to patterns in the base network - other
63+
// modifications in the scenario such as add-trips can create new patterns that don't reference any GTFS.
6164
for (TripPattern tripPattern : network.transitLayer.tripPatterns) {
6265
String feedId = feedIdForTripPattern(tripPattern);
6366
if (isNullOrEmpty(feedId)) {
@@ -80,15 +83,23 @@ public boolean apply(TransportNetwork network) {
8083

8184
// During raptor search, paths are recorded in terms of pattern and stop index numbers rather than
8285
// TripPattern and Stop instance references, so iterate over the numbers.
83-
for (int patternIndex = 0; patternIndex < network.transitLayer.tripPatterns.size(); patternIndex++) {
84-
TripPattern tripPattern = network.transitLayer.tripPatterns.get(patternIndex);
86+
final List<TripPattern> patterns = network.transitLayer.tripPatterns;
87+
for (int patternIndex = 0; patternIndex < patterns.size(); patternIndex++) {
88+
TripPattern tripPattern = patterns.get(patternIndex);
8589
// Make a sacrificial protective copy to avoid interfering with other requests using this network.
8690
// We're going to add shape data to this TripPattern then throw it away immediately afterward.
8791
// Be careful not to use a reference to this clone as a key in any Maps, it will not match TransitLayer.
8892
tripPattern = tripPattern.clone();
8993
String feedId = feedIdForTripPattern(tripPattern);
9094
GTFSFeed feed = feedForUnscopedId.get(feedId);
91-
TransitLayer.addShapeToTripPattern(feed, tripPattern);
95+
if (feed == null) {
96+
// We could not find any feed ID on this pattern, or the apparent feed ID does not match any known feed.
97+
// Since feeds for all patterns were all verified in apply(), this means the pattern must have been
98+
// added by another modification in the scenario.
99+
nPatternsWithoutGtfs += 1;
100+
} else {
101+
TransitLayer.addShapeToTripPattern(feed, tripPattern);
102+
}
92103
if (tripPattern.shape == null) {
93104
nPatternsWithoutShapes += 1;
94105
}
@@ -105,9 +116,14 @@ public boolean apply(TransportNetwork network) {
105116
hopsInTripPattern.put(patternIndex, intersectedHops.toArray());
106117
}
107118
}
119+
if (nPatternsWithoutGtfs > 0) {
120+
addInfo("Of %d patterns, %d did not reference any GTFS (apparently generated by scenario).".formatted(
121+
patterns.size(), nPatternsWithoutGtfs
122+
));
123+
}
108124
if (nPatternsWithoutShapes > 0) {
109-
addInfo( "Out of %d patterns, %d had no shapes and used straight lines.".formatted(
110-
network.transitLayer.tripPatterns.size(), nPatternsWithoutShapes
125+
addInfo("Of %d patterns, %d had no shapes and used straight lines.".formatted(
126+
patterns.size(), nPatternsWithoutShapes
111127
));
112128
}
113129
// After finding all links (TripPattern hops) in the SelectedLink area, release the GTFSFeeds which don't really

0 commit comments

Comments
 (0)