Search in sources :

Example 21 with StopTimeEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl in project onebusaway-application-modules by camsys.

the class DistanceAlongShapeLibrary method checkFirstAndLastStop.

/**
 * Special check for an issue with start points where the first stop isn't all
 * that near the start of the shape (the first stop being more of a layover
 * point). If the shape is working against us, the closest point for the first
 * stop can be a point further along the shape, which causes problems.
 */
private void checkFirstAndLastStop(List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments, ShapePoints shapePoints, UTMProjection projection, List<XYPoint> projectedShapePoints) {
    if (possibleAssignments.size() >= 2) {
        PointAndIndex first = possibleAssignments.get(0).get(0);
        PointAndIndex second = possibleAssignments.get(1).get(0);
        if (first.distanceAlongShape > second.distanceAlongShape) {
            StopTimeEntryImpl firstStopTime = stopTimes.get(0);
            _log.warn("snapping first stop time id=" + firstStopTime.getId() + " to start of shape");
            XYPoint point = projectedShapePoints.get(0);
            StopEntryImpl stop = firstStopTime.getStop();
            XYPoint stopPoint = projection.forward(stop.getStopLocation());
            double d = stopPoint.getDistance(point);
            possibleAssignments.get(0).add(new PointAndIndex(point, 0, d, 0.0));
        }
        int n = possibleAssignments.size();
        PointAndIndex prev = possibleAssignments.get(n - 2).get(0);
        PointAndIndex last = possibleAssignments.get(n - 1).get(0);
        if (prev.distanceAlongShape > last.distanceAlongShape) {
        }
    }
    if (possibleAssignments.size() > 0) {
        /**
         * We snap the last stop to the end of the shape and add it to the set of
         * possible assignments. In the worst case, it will be a higher-scoring
         * assignment and ignored, but it can help in cases where the stop was
         * weirdly assigned.
         */
        PointAndIndex lastSnapped = getLastStopSnappedToEndOfShape(stopTimes, shapePoints, projection, projectedShapePoints);
        possibleAssignments.get(possibleAssignments.size() - 1).add(lastSnapped);
    }
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 22 with StopTimeEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactory method processStopTimes.

public List<StopTimeEntryImpl> processStopTimes(TransitGraphImpl graph, List<StopTime> stopTimes, TripEntryImpl tripEntry, ShapePoints shapePoints) {
    // In case the list is unmodifiable
    // stopTimes = new ArrayList<StopTime>(stopTimes);
    ArrayList<StopTime> newStopTimes = new ArrayList<StopTime>(stopTimes.size());
    for (StopTime stopTime : stopTimes) {
        if (stopTime != null && stopTime.getStop() != null && stopTime.getStop().getId() != null) {
            newStopTimes.add(stopTime);
        } else {
            _log.error("found stopTime without a stop id for tripEntry=" + tripEntry + "(" + (stopTime.getTrip() == null ? "NuLl" : stopTime.getTrip().getId()) + ")" + "; stop=" + stopTime.getStopHeadsign() + ":" + stopTime.getArrivalTime() + ":" + stopTime.getDepartureTime() + ":" + stopTime.getRouteShortName() + "; route=" + (tripEntry.getRoute() == null ? "NuLl" : tripEntry.getRoute().getId()) + "; blockId=" + (tripEntry.getBlock() == null ? "NuLl" : tripEntry.getBlock().getId()) + "; stop=" + (stopTime.getStop() == null ? "NuLl" : stopTime.getId() + ":" + stopTime.getRouteShortName()));
        }
    }
    stopTimes = newStopTimes;
    Collections.sort(stopTimes, new StopTimeComparator());
    if (removeTimePoints) {
        stopTimes = removeTimePoints(stopTimes);
    }
    List<StopTimeEntryImpl> stopTimeEntries = createInitialStopTimeEntries(graph, stopTimes);
    for (StopTimeEntryImpl stopTime : stopTimeEntries) {
        stopTime.setTrip(tripEntry);
        stopTime.setTotalStopsInTrip(stopTimeEntries.size());
    }
    ensureStopTimesHaveShapeDistanceTraveledSet(stopTimeEntries, shapePoints);
    removeDuplicateStopTimes(stopTimes);
    ensureStopTimesHaveTimesSet(stopTimes, stopTimeEntries);
    return stopTimeEntries;
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) ArrayList(java.util.ArrayList) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 23 with StopTimeEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl 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)

Example 24 with StopTimeEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactory method getDistanceTraveledForStopTimes.

private double[] getDistanceTraveledForStopTimes(List<StopTimeEntryImpl> stopTimeEntries) {
    double[] distances = new double[stopTimeEntries.size()];
    for (int i = 0; i < stopTimeEntries.size(); i++) {
        StopTimeEntryImpl stopTime = stopTimeEntries.get(i);
        distances[i] = stopTime.getShapeDistTraveled();
    }
    return distances;
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 25 with StopTimeEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactory method createInitialStopTimeEntries.

private List<StopTimeEntryImpl> createInitialStopTimeEntries(TransitGraphImpl graph, List<StopTime> stopTimes) {
    List<StopTimeEntryImpl> stopTimeEntries = new ArrayList<StopTimeEntryImpl>(stopTimes.size());
    int sequence = 0;
    for (StopTime stopTime : stopTimes) {
        if (stopTime == null) {
            _log.error("Found null stopTime in stopTime=" + stopTimes);
            continue;
        }
        Stop stop = stopTime.getStop();
        if (stop == null) {
            _log.error("Stop is null for stopTime" + stopTime.getId());
            continue;
        }
        if (stop.getId() == null) {
            _log.error("Stop id is null for stopTime" + stopTime + ", stop=" + stop);
            continue;
        }
        AgencyAndId stopId = stop.getId();
        StopEntryImpl stopEntry = graph.getStopEntryForId(stopId);
        StopTimeEntryImpl stopTimeEntry = new StopTimeEntryImpl();
        stopTimeEntry.setId(stopTime.getId());
        stopTimeEntry.setSequence(sequence);
        stopTimeEntry.setGtfsSequence(stopTime.getStopSequence());
        stopTimeEntry.setDropOffType(stopTime.getDropOffType());
        stopTimeEntry.setPickupType(stopTime.getPickupType());
        stopTimeEntry.setStop(stopEntry);
        stopTimeEntries.add(stopTimeEntry);
        sequence++;
    }
    return stopTimeEntries;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) ArrayList(java.util.ArrayList) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) StopTime(org.onebusaway.gtfs.model.StopTime) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Aggregations

StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)32 Test (org.junit.Test)15 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)14 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)12 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)10 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)10 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)9 StopTime (org.onebusaway.gtfs.model.StopTime)7 ArrayList (java.util.ArrayList)6 XYPoint (org.onebusaway.geospatial.model.XYPoint)6 Stop (org.onebusaway.gtfs.model.Stop)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)5 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)5 Agency (org.onebusaway.gtfs.model.Agency)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 Trip (org.onebusaway.gtfs.model.Trip)4 DistanceAlongShapeLibrary (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary)4 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)4 Date (java.util.Date)3