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);
}
}
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;
}
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;
}
}
}
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;
}
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;
}
Aggregations