Search in sources :

Example 6 with ShapePoints

use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.

the class BlockConfigurationEntriesFactory method computeGapDistancesBetweenTrips.

private double[] computeGapDistancesBetweenTrips(List<TripEntry> trips) {
    double[] tripGapDistances = new double[trips.size()];
    if (_shapePointHelper == null)
        return tripGapDistances;
    for (int index = 0; index < trips.size() - 1; index++) {
        TripEntry tripA = trips.get(index);
        TripEntry tripB = trips.get(index + 1);
        double d = 0;
        ShapePoints shapeFrom = _shapePointHelper.getShapePointsForShapeId(tripA.getShapeId());
        ShapePoints shapeTo = _shapePointHelper.getShapePointsForShapeId(tripB.getShapeId());
        if (shapeFrom != null && shapeTo != null && !shapeFrom.isEmpty() && !shapeTo.isEmpty()) {
            int n = shapeFrom.getSize();
            double lat1 = shapeFrom.getLatForIndex(n - 1);
            double lon1 = shapeFrom.getLonForIndex(n - 1);
            double lat2 = shapeTo.getLatForIndex(0);
            double lon2 = shapeTo.getLonForIndex(0);
            d = SphericalGeometryLibrary.distance(lat1, lon1, lat2, lon2);
        }
        tripGapDistances[index] = d;
    }
    return tripGapDistances;
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 7 with ShapePoints

use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTaskTest method testGenerateShapePointNarratives.

@Test
public void testGenerateShapePointNarratives() {
    AgencyAndId shapeId = aid("shapeId");
    ShapePoints points = new ShapePoints();
    Mockito.when(_shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(points);
    Mockito.when(_gtfsDao.getAllShapeIds()).thenReturn(Arrays.asList(shapeId));
    _task.generateShapePointNarratives(_provider);
    Mockito.verify(_shapePointHelper).getShapePointsForShapeId(shapeId);
    assertSame(points, _provider.getShapePointsForId(shapeId));
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 8 with ShapePoints

use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithConflictingDirections.

@Test
public void testGenerateStopNarrativesWithConflictingDirections() {
    StopEntryImpl stopEntry = stop("stopA", 47.663146, -122.300928);
    Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopEntry));
    Stop stop = new Stop();
    stop.setId(stopEntry.getId());
    Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
    /**
     * Two shapes heading in opposite directions
     */
    AgencyAndId shapeIdA = aid("shapeA");
    ShapePointsFactory factoryA = new ShapePointsFactory();
    factoryA.addPoint(47.661225, -122.3009201);
    factoryA.addPoint(47.664375, -122.3008986);
    ShapePoints shapePointsA = factoryA.create();
    _provider.setShapePointsForId(shapeIdA, shapePointsA);
    AgencyAndId shapeIdB = aid("shapeB");
    ShapePointsFactory factoryB = new ShapePointsFactory();
    factoryB.addPoint(47.664375, -122.3008986);
    factoryB.addPoint(47.661225, -122.3009201);
    ShapePoints shapePointsB = factoryB.create();
    _provider.setShapePointsForId(shapeIdB, shapePointsB);
    TripEntryImpl tripA = trip("tripA");
    tripA.setShapeId(shapeIdA);
    TripEntryImpl tripB = trip("tripB");
    tripB.setShapeId(shapeIdB);
    StopTimeEntryImpl stopTimeA = stopTime(0, stopEntry, tripA, 0, 0.0);
    stopTimeA.setShapePointIndex(0);
    StopTimeEntryImpl stopTimeB = stopTime(0, stopEntry, tripB, 0, 0.0);
    stopTimeB.setShapePointIndex(0);
    BlockStopTimeEntry blockStopTimeA = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeA.getStopTime()).thenReturn(stopTimeA);
    BlockStopTimeEntry blockStopTimeB = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeB.getStopTime()).thenReturn(stopTimeB);
    BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
    Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTimeA, blockStopTimeB));
    List<BlockStopTimeIndex> indices = Arrays.asList(index);
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
    _task.generateStopNarratives(_provider);
    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertNull(narrative.getDirection());
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 9 with ShapePoints

use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithCalculatedDirection.

@Test
public void testGenerateStopNarrativesWithCalculatedDirection() {
    StopEntryImpl stopEntry = stop("stopA", 47.663146, -122.300928);
    Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopEntry));
    Stop stop = new Stop();
    stop.setId(stopEntry.getId());
    Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
    AgencyAndId shapeId = aid("shapeA");
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.661225, -122.3009201);
    factory.addPoint(47.664375, -122.3008986);
    ShapePoints shapePoints = factory.create();
    _provider.setShapePointsForId(shapeId, shapePoints);
    TripEntryImpl trip = trip("trip");
    trip.setShapeId(shapeId);
    StopTimeEntryImpl stopTime = stopTime(0, stopEntry, trip, 0, 0.0);
    stopTime.setShapePointIndex(0);
    BlockStopTimeEntry blockStopTime = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTime.getStopTime()).thenReturn(stopTime);
    BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
    Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTime));
    List<BlockStopTimeIndex> indices = Arrays.asList(index);
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
    _task.generateStopNarratives(_provider);
    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertEquals("N", narrative.getDirection());
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 10 with ShapePoints

use of org.onebusaway.transit_data_federation.model.ShapePoints in project onebusaway-application-modules by camsys.

the class DistanceAlongShapeLibraryTest method test03.

@Test
public void test03() throws IOException, DistanceAlongShapeException {
    ShapePoints shapePoints = readShapePoints("shapes-03.txt");
    List<StopTimeEntryImpl> stopTimes = readStopTimes("stops-03.txt");
    DistanceAlongShapeLibrary library = new DistanceAlongShapeLibrary();
    PointAndIndex[] points = library.getDistancesAlongShape(shapePoints, stopTimes);
    assertEquals(5, points.length);
    // STOP A
    assertEquals(67.9, points[0].distanceAlongShape, 0.1);
    assertEquals(0, points[0].index);
    // STOP B
    assertEquals(446.0, points[1].distanceAlongShape, 0.1);
    assertEquals(1, points[1].index);
    // STOP C
    assertEquals(852.7, points[2].distanceAlongShape, 0.1);
    assertEquals(2, points[2].index);
    // STOP D
    assertEquals(1247.0, points[3].distanceAlongShape, 0.1);
    assertEquals(3, points[3].index);
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) Test(org.junit.Test)

Aggregations

ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)26 Test (org.junit.Test)13 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)12 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)10 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)9 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)8 Stop (org.onebusaway.gtfs.model.Stop)6 Agency (org.onebusaway.gtfs.model.Agency)5 StopTime (org.onebusaway.gtfs.model.StopTime)5 Route (org.onebusaway.gtfs.model.Route)4 Trip (org.onebusaway.gtfs.model.Trip)4 DistanceAlongShapeLibrary (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary)4 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)4 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)4 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 ArrayList (java.util.ArrayList)3 Cacheable (org.onebusaway.container.cache.Cacheable)3 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)3 StopTimeEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory)3