Search in sources :

Example 1 with DistanceAlongShapeException

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;
        }
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) DistanceAlongShapeException(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.DistanceAlongShapeException) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) StopIsTooFarFromShapeException(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.StopIsTooFarFromShapeException) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)

Aggregations

CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 DistanceAlongShapeException (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.DistanceAlongShapeException)1 StopIsTooFarFromShapeException (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.StopIsTooFarFromShapeException)1 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)1 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1