Skip to content

Commit da5450f

Browse files
fix: update TripAndShapeDistanceValidator to ignore shape with no shape_dist_traveled (#2018)
Some GTFS feeds do not provide shape_dist_traveled in shapes.txt In this case, the value is set to 0 in the code, so sorting shapes based on ShapeDistTraveled does not work and usually returns the first shape row. It leads to an error, the first shape of the shape is usually very far away from the last stop of the trips following the shape. We can assume the biggest shape_dist_traveled of a given shape should never be 0, otherwise it means the value is not set. In this case, we return early to ensure no validation error will be issued. Fixes #2018
1 parent f1174bd commit da5450f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

main/src/main/java/org/mobilitydata/gtfsvalidator/validator/TripAndShapeDistanceValidator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public void validate(NoticeContainer noticeContainer) {
8484
}
8585

8686
double maxShapeDist = maxShape.shapeDistTraveled();
87+
88+
if (maxShapeDist == 0) {
89+
return;
90+
}
91+
8792
double distanceInMeters =
8893
getDistanceMeters(maxShape.shapePtLatLon(), stop.stopLatLon());
8994
if (maxStopTimeDist > maxShapeDist) {

main/src/test/java/org/mobilitydata/gtfsvalidator/validator/TripAndShapeDistanceValidatorTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ public void testTripDistanceExceedsShapeDistance() {
108108
assertThat(found).isTrue();
109109
}
110110

111+
@Test
112+
public void testTripDistanceExceedsShapeDistanceNoShapeDistance() {
113+
List<ValidationNotice> notices =
114+
generateNotices(
115+
createTripTable(2),
116+
createStopTimesTable(1, 10.0),
117+
createShapeTable(1, 0.0, 10.0),
118+
createStopTable(1));
119+
boolean found =
120+
notices.stream()
121+
.anyMatch(
122+
notice ->
123+
notice
124+
instanceof
125+
TripAndShapeDistanceValidator.TripDistanceExceedsShapeDistanceNotice);
126+
assertThat(found).isFalse();
127+
}
128+
111129
@Test
112130
public void testTripDistanceExceedsShapeDistanceWarning() {
113131
List<ValidationNotice> notices =

0 commit comments

Comments
 (0)