Search in sources :

Example 76 with Stop

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);
    }
}
Also used : ShapePoint(org.onebusaway.gtfs.model.ShapePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopLocation(org.onebusaway.gtfs.model.StopLocation) ShapePoint(org.onebusaway.gtfs.model.ShapePoint)

Example 77 with Stop

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;
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList)

Example 78 with Stop

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList)

Example 79 with Stop

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);
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Stop(org.onebusaway.gtfs.model.Stop) GtfsReaderContext(org.onebusaway.gtfs.serialization.GtfsReaderContext) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 80 with Stop

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);
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) StopLocation(org.onebusaway.gtfs.model.StopLocation) StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)160 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)75 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Trip (org.onebusaway.gtfs.model.Trip)40 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)33 StopTime (org.onebusaway.gtfs.model.StopTime)33 Route (org.onebusaway.gtfs.model.Route)28 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)23 Agency (org.onebusaway.gtfs.model.Agency)19 Vertex (org.opentripplanner.routing.graph.Vertex)18 HashMap (java.util.HashMap)14 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)13 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)11 LineString (com.vividsolutions.jts.geom.LineString)10 List (java.util.List)10 GET (javax.ws.rs.GET)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10 GraphPath (org.opentripplanner.routing.spt.GraphPath)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)9