Search in sources :

Example 16 with StopTimeEntryImpl

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

the class UnitTestingSupport method stopTime.

public static StopTimeEntryImpl stopTime(int id, StopEntryImpl stop, TripEntryImpl trip, int arrivalTime, int departureTime, double shapeDistTraveled, int shapeIndex) {
    StopTimeEntryImpl stopTime = new StopTimeEntryImpl();
    stopTime.setId(id);
    stopTime.setStop(stop);
    stopTime.setArrivalTime(arrivalTime);
    stopTime.setDepartureTime(departureTime);
    stopTime.setShapeDistTraveled(shapeDistTraveled);
    stopTime.setShapePointIndex(shapeIndex);
    if (trip != null)
        addStopTime(trip, stopTime);
    return stopTime;
}
Also used : BlockStopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockStopTimeEntryImpl) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)

Example 17 with StopTimeEntryImpl

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

the class DistanceAlongShapeLibrary method computeBestAssignment.

private List<PointAndIndex> computeBestAssignment(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments, UTMProjection projection, List<XYPoint> projectedShapePoints) throws InvalidStopToShapeMappingException {
    checkFirstAndLastStop(stopTimes, possibleAssignments, shapePoints, projection, projectedShapePoints);
    int startIndex = 0;
    int assingmentCount = 1;
    /**
     * We iterate over each stop, examining its possible assignments. If we find
     * a region of stops where the first and last stop have a single assignment
     * but the stops in-between have multiple assignments, we compute the best
     * assignments for that section. We also handle the edge-cases where the
     * multiple potential assignments occur at the start or end of the route.
     */
    for (int index = 0; index < possibleAssignments.size(); index++) {
        List<PointAndIndex> possibleAssignment = possibleAssignments.get(index);
        int count = possibleAssignment.size();
        if (count == 0) {
            constructErrorForPotentialAssignmentCount(shapePoints, stopTimes, count);
        }
        boolean hasRegion = index > startIndex;
        boolean hasSingleAssignmentFollowingMultipleAssignments = count == 1 && assingmentCount > 1;
        boolean hasMultipleAssignmentsAndLastPoint = count > 1 && index == possibleAssignments.size() - 1;
        if (hasRegion && (hasSingleAssignmentFollowingMultipleAssignments || hasMultipleAssignmentsAndLastPoint)) {
            List<PointAndIndex> currentAssignment = new ArrayList<PointAndIndex>(index - startIndex + 1);
            Min<Assignment> bestAssignments = new Min<Assignment>();
            recursivelyConstructAssignments(possibleAssignments, currentAssignment, startIndex, startIndex, index + 1, bestAssignments);
            if (bestAssignments.isEmpty()) {
                constructError(shapePoints, stopTimes, possibleAssignments, projection);
            } else {
                List<PointAndIndex> bestAssignment = bestAssignments.getMinElement().assigment;
                for (int bestIndex = 0; bestIndex < bestAssignment.size(); bestIndex++) {
                    possibleAssignments.set(startIndex + bestIndex, Arrays.asList(bestAssignment.get(bestIndex)));
                }
            }
        }
        if (count == 1) {
            startIndex = index;
            assingmentCount = 1;
        } else {
            assingmentCount *= count;
            if (assingmentCount > _maximumNumberOfPotentialAssignments) {
                constructErrorForPotentialAssignmentCount(shapePoints, stopTimes, assingmentCount);
            }
        }
    }
    List<PointAndIndex> bestAssignment = new ArrayList<PointAndIndex>();
    for (List<PointAndIndex> possibleAssignment : possibleAssignments) {
        if (possibleAssignment.size() != 1) {
            String msg = "expected just one assignment at this point, found " + possibleAssignment.size() + "; " + "shapePoint=" + shapePoints.getShapeId() + ", " + "\npossibleAssignments=\n";
            for (PointAndIndex pa : possibleAssignment) {
                msg += "PointAndIndex(index=" + pa.index + ", point=" + pa.point + ", distanceAlongShape=" + pa.distanceAlongShape + ", distanceFromTarget=" + pa.distanceFromTarget + "), ";
            }
            msg += "\nstopTime=\n";
            for (StopTimeEntryImpl st : stopTimes) {
                msg += "StopTimeEntry(Stop(" + st.getStop().getId() + ":" + st.getStop().getStopLat() + ", " + st.getStop().getStopLon() + ")" + ", trip=" + st.getTrip().getId() + "), ";
            }
            _log.error(msg);
            if (!_lenientStopShapeAssignment)
                throw new IllegalStateException(msg);
        }
        bestAssignment.add(possibleAssignment.get(0));
    }
    return bestAssignment;
}
Also used : Min(org.onebusaway.collections.Min) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) ArrayList(java.util.ArrayList) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint)

Example 18 with StopTimeEntryImpl

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

the class DistanceAlongShapeLibrary method getLastStopSnappedToEndOfShape.

private PointAndIndex getLastStopSnappedToEndOfShape(List<StopTimeEntryImpl> stopTimes, ShapePoints shapePoints, UTMProjection projection, List<XYPoint> projectedShapePoints) {
    int i = stopTimes.size() - 1;
    StopTimeEntryImpl lastStopTime = stopTimes.get(i);
    int lastShapePointIndex = projectedShapePoints.size() - 1;
    XYPoint lastShapePoint = projectedShapePoints.get(lastShapePointIndex);
    XYPoint stopLocation = projection.forward(lastStopTime.getStop().getStopLocation());
    double existingDistanceAlongShape = shapePoints.getDistTraveledForIndex(lastShapePointIndex);
    double extraDistanceAlongShape = lastShapePoint.getDistance(stopLocation);
    double distanceAlongShape = existingDistanceAlongShape + extraDistanceAlongShape;
    double d = lastShapePoint.getDistance(stopLocation);
    return new PointAndIndex(lastShapePoint, lastShapePointIndex, d, distanceAlongShape);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint)

Example 19 with StopTimeEntryImpl

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

the class DistanceAlongShapeLibrary method computePotentialAssignments.

private List<List<PointAndIndex>> computePotentialAssignments(UTMProjection projection, List<XYPoint> projectedShapePoints, double[] shapePointDistance, List<StopTimeEntryImpl> stopTimes) {
    List<List<PointAndIndex>> possibleAssignments = new ArrayList<List<PointAndIndex>>();
    for (StopTimeEntryImpl stopTime : stopTimes) {
        StopEntryImpl stop = stopTime.getStop();
        XYPoint stopPoint = projection.forward(stop.getStopLocation());
        List<PointAndIndex> assignments = _shapePointsLibrary.computePotentialAssignments(projectedShapePoints, shapePointDistance, stopPoint, 0, projectedShapePoints.size());
        possibleAssignments.add(assignments);
    }
    return possibleAssignments;
}
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) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 20 with StopTimeEntryImpl

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

the class DistanceAlongShapeLibrary method constructErrorForPotentialAssignmentCount.

private void constructErrorForPotentialAssignmentCount(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, long count) throws InvalidStopToShapeMappingException {
    if (count == 0) {
        _log.error("We were attempting to compute the distance along a particular trip for each stop time of that " + "trip by snapping them to the shape for that trip.  However, we could not find an assignment for each " + "stop time of the trip, which usually indicates that there is something wrong with the underlying " + "shape data.  For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    } else {
        _log.error("We were attempting to compute the distance along a particular trip for each stop time of that " + "trip by snapping them to the shape for that trip.  However, we found WAY TOO MANY potential " + "assignments, which usually indicates that there is something wrong with the underlying shape data.  " + "For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    }
    StopTimeEntryImpl first = stopTimes.get(0);
    TripEntryImpl trip = first.getTrip();
    StopTimeEntryImpl last = stopTimes.get(stopTimes.size() - 1);
    _log.error("error constructing stop-time distances along shape for trip=" + trip.getId() + " shape=" + trip.getShapeId() + " firstStopTime=" + first.getId() + " lastStopTime=" + last.getId());
    if (_shapeIdsWeHavePrinted.add(trip.getShapeId())) {
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < shapePoints.getSize(); i++) {
            b.append(shapePoints.getLatForIndex(i));
            b.append(' ');
            b.append(shapePoints.getLonForIndex(i));
            b.append(' ');
            b.append(shapePoints.getDistTraveledForIndex(i));
            b.append('\n');
        }
        _log.error("shape points:\n" + b.toString());
    }
    throw new InvalidStopToShapeMappingException(first.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint)

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