use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.
the class TripEntriesFactory method processTrip.
private TripEntryImpl processTrip(TransitGraphImpl graph, Trip trip) {
List<StopTime> stopTimes = _gtfsDao.getStopTimesForTrip(trip);
// A trip without stop times is a trip we don't care about
if (stopTimes.isEmpty())
return null;
ShapePoints shapePoints = null;
if (trip.getShapeId() != null)
shapePoints = _shapePointsHelper.getShapePointsForShapeId(trip.getShapeId());
Agency agency = trip.getRoute().getAgency();
TimeZone tz = TimeZone.getTimeZone(agency.getTimezone());
LocalizedServiceId lsid = new LocalizedServiceId(trip.getServiceId(), tz);
TripEntryImpl tripEntry = new TripEntryImpl();
tripEntry.setId(trip.getId());
tripEntry.setDirectionId(unique(trip.getDirectionId()));
tripEntry.setServiceId(unique(lsid));
// back it up
if (!(shapePoints == null || shapePoints.isEmpty()))
tripEntry.setShapeId(unique(trip.getShapeId()));
List<StopTimeEntryImpl> stopTimesForTrip = _stopTimeEntriesFactory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
// Also: only set the trip if there are stops for it
if (stopTimesForTrip == null || stopTimesForTrip.size() < 2) {
_log.error("trip " + trip.getId() + " missing stops!");
return null;
}
double tripDistance = getTripDistance(stopTimesForTrip, shapePoints);
tripEntry.setTotalTripDistance(tripDistance);
tripEntry.setStopTimes(cast(stopTimesForTrip));
graph.putTripEntry(tripEntry);
return tripEntry;
}
use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibraryTest method test02.
@Test
public void test02() throws IOException, DistanceAlongShapeException {
ShapePoints shapePoints = readShapePoints("shapes-02.txt");
List<StopTimeEntryImpl> stopTimes = readStopTimes("stops-02.txt");
DistanceAlongShapeLibrary library = new DistanceAlongShapeLibrary();
PointAndIndex[] points = library.getDistancesAlongShape(shapePoints, stopTimes);
assertEquals(4, points.length);
// STOP A
assertEquals(155.4, points[0].distanceAlongShape, 0.1);
assertEquals(1, points[0].index);
// STOP B
assertEquals(816.7, points[1].distanceAlongShape, 0.1);
assertEquals(4, points[1].index);
// STOP C
assertEquals(819.3, points[2].distanceAlongShape, 0.1);
assertEquals(5, points[2].index);
// STOP D
assertEquals(1151.1, points[3].distanceAlongShape, 0.1);
assertEquals(9, points[3].index);
}
use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactoryTest method testThreeInARowDuplicateRemoval.
@Test
public void testThreeInARowDuplicateRemoval() {
TransitGraphImpl graph = new TransitGraphImpl();
Stop stopA = new Stop();
stopA.setId(aid("stopA"));
graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
Stop stopB = new Stop();
stopB.setId(aid("stopB"));
graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
Stop stopC = new Stop();
stopC.setId(aid("stopC"));
graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
Stop stopD = new Stop();
stopD.setId(aid("stopD"));
graph.putStopEntry(stop("stopD", 47.66947942216854, -122.37545336180114));
graph.refreshStopMapping();
Agency agency = new Agency();
agency.setId("1");
agency.setTimezone("America/Los_Angeles");
Route route = new Route();
route.setAgency(agency);
Trip trip = new Trip();
trip.setRoute(route);
trip.setServiceId(aid("serviceId"));
TripEntryImpl tripEntry = trip("trip");
StopTime stA = new StopTime();
stA.setId(100);
stA.setArrivalTime(time(9, 00));
stA.setDepartureTime(time(9, 05));
stA.setStopSequence(100);
stA.setStop(stopA);
stA.setTrip(trip);
StopTime stB = new StopTime();
stB.setId(101);
stB.setArrivalTime(time(9, 00));
stB.setDepartureTime(time(9, 05));
stB.setStopSequence(101);
stB.setStop(stopB);
stB.setTrip(trip);
StopTime stC = new StopTime();
stC.setId(102);
stC.setArrivalTime(time(9, 00));
stC.setDepartureTime(time(9, 05));
stC.setStopSequence(102);
stC.setStop(stopC);
stC.setTrip(trip);
StopTime stD = new StopTime();
stD.setId(103);
stD.setArrivalTime(time(11, 00));
stD.setDepartureTime(time(11, 05));
stD.setStopSequence(103);
stD.setStop(stopD);
stD.setTrip(trip);
StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
List<StopTime> stopTimes = Arrays.asList(stA, stB, stC, stD);
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
shapePointsFactory.addPoint(47.66947942216854, -122.37545336180114);
ShapePoints shapePoints = shapePointsFactory.create();
List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
assertEquals(stopTimes.size(), entries.size());
StopTimeEntryImpl entry = entries.get(0);
assertEquals(0, entry.getAccumulatedSlackTime());
assertEquals(time(9, 00), entry.getArrivalTime());
assertEquals(time(9, 05), entry.getDepartureTime());
assertEquals(0, entry.getSequence());
assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
assertEquals(5 * 60, entry.getSlackTime());
entry = entries.get(1);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(9, 28, 45), entry.getArrivalTime());
assertEquals(time(9, 28, 45), entry.getDepartureTime());
assertEquals(1, entry.getSequence());
assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
assertEquals(0, entry.getSlackTime());
entry = entries.get(2);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(10, 00, 34), entry.getArrivalTime());
assertEquals(time(10, 00, 34), entry.getDepartureTime());
assertEquals(2, entry.getSequence());
assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
assertEquals(0, entry.getSlackTime());
entry = entries.get(3);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(11, 00), entry.getArrivalTime());
assertEquals(time(11, 05), entry.getDepartureTime());
assertEquals(3, entry.getSequence());
assertEquals(2877.69, entry.getShapeDistTraveled(), 0.1);
assertEquals(60 * 5, entry.getSlackTime());
}
use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.
the class TripEntriesFactoryTest method test.
@Test
public void test() {
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
Agency agency = new Agency();
agency.setId("1");
agency.setTimezone("America/Los_Angeles");
// gtfsDao.saveEntity(agency);
Route route = new Route();
route.setId(new AgencyAndId("1", "routeA"));
route.setAgency(agency);
Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(route));
AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "tripA"));
trip.setRoute(route);
trip.setServiceId(new AgencyAndId("1", "serviceId"));
trip.setShapeId(shapeId);
Mockito.when(gtfsDao.getTripsForRoute(route)).thenReturn(Arrays.asList(trip));
Stop stopA = new Stop();
stopA.setId(aid("stopA"));
StopTime stA = new StopTime();
stA.setId(100);
stA.setArrivalTime(time(9, 00));
stA.setDepartureTime(time(9, 05));
stA.setStopSequence(100);
stA.setStop(stopA);
stA.setTrip(trip);
Stop stopB = new Stop();
stopB.setId(aid("stopB"));
StopTime stB = new StopTime();
stB.setId(101);
stB.setArrivalTime(time(10, 00));
stB.setDepartureTime(time(10, 05));
stB.setStopSequence(102);
stB.setStop(stopB);
stB.setTrip(trip);
Mockito.when(gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stA, stB));
TransitGraphImpl graph = new TransitGraphImpl();
graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
RouteEntryImpl routeEntry = route("routeA");
graph.putRouteEntry(routeEntry);
graph.initialize();
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
ShapePoints shapePoints = shapePointsFactory.create();
ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(shapePoints);
TripEntriesFactory factory = new TripEntriesFactory();
factory.setGtfsDao(gtfsDao);
factory.setShapePointHelper(shapePointHelper);
factory.setUniqueService(new UniqueServiceImpl());
StopTimeEntriesFactory stopTimeEntriesFactory = new StopTimeEntriesFactory();
stopTimeEntriesFactory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
factory.setStopTimeEntriesFactory(stopTimeEntriesFactory);
factory.processTrips(graph);
TripEntryImpl entry = graph.getTripEntryForId(trip.getId());
assertEquals(trip.getId(), entry.getId());
assertEquals(route.getId(), entry.getRoute().getId());
assertEquals(lsid("serviceId"), entry.getServiceId());
assertEquals(trip.getShapeId(), entry.getShapeId());
assertEquals(2177.1, entry.getTotalTripDistance(), 0.1);
List<StopTimeEntry> stopTimes = entry.getStopTimes();
assertEquals(2, stopTimes.size());
for (StopTimeEntry stopTime : stopTimes) {
assertSame(entry, stopTime.getTrip());
}
}
use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.
the class ProjectedShapePointServiceImpl method getProjectedShapePoints.
@Cacheable
@Override
public T2<List<XYPoint>, double[]> getProjectedShapePoints(List<AgencyAndId> shapeIds, int utmZoneId) {
ShapePoints shapePoints = _shapePointService.getShapePointsForShapeIds(shapeIds);
if (shapePoints == null || shapePoints.isEmpty())
return null;
UTMProjection projection = new UTMProjection(utmZoneId);
List<XYPoint> projected = _shapePointsLibrary.getProjectedShapePoints(shapePoints, projection);
return Tuples.tuple(projected, shapePoints.getDistTraveled());
}
Aggregations