use of org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.DistanceAlongShapeException in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactory method ensureStopTimesHaveShapeDistanceTraveledSet.
/**
* We have to make sure shape distance traveled is set, even if we don't have
* shape information
*
* @param stopTimes
* @param shapePoints potentially null
*/
private void ensureStopTimesHaveShapeDistanceTraveledSet(List<StopTimeEntryImpl> stopTimes, ShapePoints shapePoints) {
boolean distanceTraveledSet = false;
// Do we have shape information?
if (shapePoints != null) {
try {
PointAndIndex[] stopTimePoints = _distanceAlongShapeLibrary.getDistancesAlongShape(shapePoints, stopTimes);
for (int i = 0; i < stopTimePoints.length; i++) {
PointAndIndex pindex = stopTimePoints[i];
StopTimeEntryImpl stopTime = stopTimes.get(i);
stopTime.setShapePointIndex(pindex.index);
stopTime.setShapeDistTraveled(pindex.distanceAlongShape);
}
distanceTraveledSet = true;
} catch (StopIsTooFarFromShapeException ex) {
StopTimeEntry stopTime = ex.getStopTime();
TripEntry trip = stopTime.getTrip();
StopEntry stop = stopTime.getStop();
AgencyAndId shapeId = trip.getShapeId();
CoordinatePoint point = ex.getPoint();
PointAndIndex pindex = ex.getPointAndIndex();
_log.warn("Stop is too far from shape: trip=" + trip.getId() + " stop=" + stop.getId() + " stopLat=" + stop.getStopLat() + " stopLon=" + stop.getStopLon() + " shapeId=" + shapeId + " shapePoint=" + point + " index=" + pindex.index + " distance=" + pindex.distanceFromTarget);
} catch (DistanceAlongShapeException ex) {
_invalidStopToShapeMappingExceptionCount++;
} catch (IllegalArgumentException iae) {
_log.warn("Stop has illegal coordinates along shapes=" + shapePoints);
}
}
if (!distanceTraveledSet) {
// Make do without
double d = 0;
StopTimeEntryImpl prev = null;
for (StopTimeEntryImpl stopTime : stopTimes) {
if (prev != null) {
CoordinatePoint from = prev.getStop().getStopLocation();
CoordinatePoint to = stopTime.getStop().getStopLocation();
d += SphericalGeometryLibrary.distance(from, to);
}
stopTime.setShapeDistTraveled(d);
prev = stopTime;
}
}
}
Aggregations