use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class TrimTripTransformStrategy method updateShape.
private void updateShape(GtfsMutableRelationalDao dao, Trip trip, List<StopTime> stopTimes, Set<AgencyAndId> newShapeIds) {
if (stopTimes.size() < 2) {
trip.setShapeId(null);
return;
}
AgencyAndId shapeId = trip.getShapeId();
if (shapeId == null || !shapeId.hasValues()) {
return;
}
List<ShapePoint> points = dao.getShapePointsForShapeId(shapeId);
if (points.isEmpty()) {
return;
}
StopLocation firstStop = stopTimes.get(0).getStop();
StopLocation lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
String id = shapeId.getId() + "-" + firstStop.getId().getId() + "-" + lastStop.getId().getId();
AgencyAndId newShapeId = new AgencyAndId(shapeId.getAgencyId(), id);
trip.setShapeId(newShapeId);
if (!(firstStop instanceof Stop)) {
// TODO Correct error type
throw new Error(firstStop + " must be stop");
}
if (!(lastStop instanceof Stop)) {
// TODO Correct error type
throw new Error(firstStop + " must be stop");
}
if (!newShapeIds.add(newShapeId)) {
return;
}
int shapePointFrom = getClosestShapePointToStop(points, (Stop) firstStop);
int shapePointTo = getClosestShapePointToStop(points, (Stop) lastStop);
for (int index = shapePointFrom; index <= shapePointTo; ++index) {
ShapePoint point = new ShapePoint(points.get(index));
point.setId(0);
point.setShapeId(newShapeId);
dao.saveEntity(point);
}
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveStopsFromShapesStrategy method loadAllStopPoints.
private List<Coord> loadAllStopPoints(GtfsMutableRelationalDao dao) {
List<Coord> allStopPoints = new ArrayList<>();
Collection<Stop> allStops = dao.getAllStops();
for (Stop stop : allStops) {
allStopPoints.add(new Coord(stop.getLat(), stop.getLon()));
}
return allStopPoints;
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class StopTimesFactoryStrategy method getStops.
private List<Stop> getStops(GtfsReaderContext context, GtfsMutableRelationalDao dao) {
List<Stop> stops = new ArrayList<Stop>();
for (String stopId : stopIds) {
String agencyId = context.getAgencyForEntity(Stop.class, stopId);
AgencyAndId id = new AgencyAndId(agencyId, stopId);
Stop stop = dao.getStopForId(id);
if (stop == null) {
throw new IllegalArgumentException("unknown stop: " + stopId);
}
stops.add(stop);
}
return stops;
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class StopTimesFactoryStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsReaderContext gtfsReaderContext = context.getReader().getGtfsReaderContext();
Trip trip = getTrip(gtfsReaderContext, dao);
List<Stop> stops = getStops(gtfsReaderContext, dao);
int[] times = getTimesForStops(stops);
for (int i = 0; i < stops.size(); ++i) {
StopTime stopTime = new StopTime();
stopTime.setStop(stops.get(i));
stopTime.setStopSequence(i);
stopTime.setArrivalTime(times[i]);
stopTime.setDepartureTime(times[i]);
stopTime.setTrip(trip);
dao.saveEntity(stopTime);
}
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class TripKey method getTripKeyForTrip.
public static TripKey getTripKeyForTrip(GtfsMutableRelationalDao dao, Trip trip) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
StopLocation[] stops = new Stop[stopTimes.size()];
int[] arrivalTimes = new int[stopTimes.size()];
int[] departureTimes = new int[stopTimes.size()];
for (int i = 0; i < stopTimes.size(); i++) {
StopTime stopTime = stopTimes.get(i);
stops[i] = stopTime.getStop();
arrivalTimes[i] = stopTime.getArrivalTime();
departureTimes[i] = stopTime.getDepartureTime();
}
return new TripKey(stops, arrivalTimes, departureTimes);
}
Aggregations