Skip to content

Commit

Permalink
feat: threshold of 1.11m on equal_shape_distance_diff_coordinates (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y authored Mar 8, 2024
1 parent 5b923ea commit 62c7784
Showing 1 changed file with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
* <li>{@link DecreasingShapeDistanceNotice}
* <li>{@link EqualShapeDistanceSameCoordinatesNotice}
* <li>{@link EqualShapeDistanceDiffCoordinatesNotice}
* <li>{@link EqualShapeDistanceDiffCoordinatesDistanceBelowThresholdNotice}
* </ul>
*/
@GtfsValidator
public class ShapeIncreasingDistanceValidator extends FileValidator {

private final GtfsShapeTableContainer table;
private final double DISTANCE_THRESHOLD = 1.11;

@Inject
ShapeIncreasingDistanceValidator(GtfsShapeTableContainer table) {
Expand All @@ -72,8 +74,15 @@ public void validate(NoticeContainer noticeContainer) {
}
// equal shape_dist_traveled and different coordinates
if (!(curr.shapePtLon() == prev.shapePtLon() && curr.shapePtLat() == prev.shapePtLat())) {
noticeContainer.addValidationNotice(
new EqualShapeDistanceDiffCoordinatesNotice(prev, curr));
double distanceBetweenShapePoints =
getDistanceMeters(curr.shapePtLatLon(), prev.shapePtLatLon());
if (distanceBetweenShapePoints >= DISTANCE_THRESHOLD) {
noticeContainer.addValidationNotice(
new EqualShapeDistanceDiffCoordinatesNotice(prev, curr));
} else if (distanceBetweenShapePoints > 0) {
noticeContainer.addValidationNotice(
new EqualShapeDistanceDiffCoordinatesDistanceBelowThresholdNotice(prev, curr));
}
} else {
// equal shape_dist_traveled and same coordinates
noticeContainer.addValidationNotice(
Expand Down Expand Up @@ -177,7 +186,7 @@ static class EqualShapeDistanceSameCoordinatesNotice extends ValidationNotice {

/**
* Two consecutive points have equal `shape_dist_traveled` and different lat/lon coordinates in
* `shapes.txt`.
* `shapes.txt` and the distance between the two points is greater than the 1.11m.
*
* <p>When sorted by `shape.shape_pt_sequence`, the values for `shape_dist_traveled` must increase
* along a shape. Two consecutive points with equal values for `shape_dist_traveled` and different
Expand Down Expand Up @@ -209,8 +218,10 @@ static class EqualShapeDistanceDiffCoordinatesNotice extends ValidationNotice {
/** The previous record's `shapes.shape_pt_sequence`. */
private final int prevShapePtSequence;

// Actual distance traveled along the shape from the first shape point to the previous shape
/** point. */
/**
* Actual distance traveled along the shape from the first shape point to the previous shape
* point.
*/
private final double actualDistanceBetweenShapePoints;

EqualShapeDistanceDiffCoordinatesNotice(GtfsShape previous, GtfsShape current) {
Expand All @@ -225,4 +236,59 @@ static class EqualShapeDistanceDiffCoordinatesNotice extends ValidationNotice {
getDistanceMeters(current.shapePtLatLon(), previous.shapePtLatLon());
}
}

/**
* Two consecutive points have equal `shape_dist_traveled` and different lat/lon coordinates in
* `shapes.txt` and the distance between the two points is less than 1.11m.
*
* <p>When sorted by `shape.shape_pt_sequence`, the values for `shape_dist_traveled` must increase
* along a shape. Two consecutive points with equal values for `shape_dist_traveled` and small
* difference of coordinates (less than 1.11 m distance) result in a warning.
*/
@GtfsValidationNotice(
severity = WARNING,
files = @FileRefs({GtfsShapeSchema.class, GtfsStopSchema.class}))
static class EqualShapeDistanceDiffCoordinatesDistanceBelowThresholdNotice
extends ValidationNotice {

/** The id of the faulty shape. */
private final String shapeId;

/** The row number from `shapes.txt`. */
private final int csvRowNumber;

/** The faulty record's `shape_dist_traveled` value. */
private final double shapeDistTraveled;

/** The faulty record's `shapes.shape_pt_sequence`. */
private final int shapePtSequence;

/** The row number from `shapes.txt` of the previous shape point. */
private final long prevCsvRowNumber;

/** The previous shape point's `shape_dist_traveled` value. */
private final double prevShapeDistTraveled;

/** The previous record's `shapes.shape_pt_sequence`. */
private final int prevShapePtSequence;

/**
* Actual distance traveled along the shape from the first shape point to the previous shape
* point.
*/
private final double actualDistanceBetweenShapePoints;

EqualShapeDistanceDiffCoordinatesDistanceBelowThresholdNotice(
GtfsShape previous, GtfsShape current) {
this.shapeId = current.shapeId();
this.csvRowNumber = current.csvRowNumber();
this.shapeDistTraveled = current.shapeDistTraveled();
this.shapePtSequence = current.shapePtSequence();
this.prevCsvRowNumber = previous.csvRowNumber();
this.prevShapeDistTraveled = previous.shapeDistTraveled();
this.prevShapePtSequence = previous.shapePtSequence();
this.actualDistanceBetweenShapePoints =
getDistanceMeters(current.shapePtLatLon(), previous.shapePtLatLon());
}
}
}

0 comments on commit 62c7784

Please sign in to comment.