Search in sources :

Example 1 with ShapePointsFactory

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

the class ShapePointsLibraryTest method test04.

@Test
public void test04() {
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.66851509562011, -122.29019398384474);
    factory.addPoint(47.66486634286269, -122.29014033966445);
    factory.addPoint(47.66486634286269, -122.29560131721877);
    ShapePoints shapePoints = factory.create();
    UTMProjection projection = UTMLibrary.getProjectionForPoint(shapePoints.getLatForIndex(0), shapePoints.getLonForIndex(0));
    ShapePointsLibrary spl = new ShapePointsLibrary();
    List<XYPoint> projectedShapePoints = spl.getProjectedShapePoints(shapePoints, projection);
    XYPoint stopPoint = projection.forward(new CoordinatePoint(47.664922340500475, -122.29066873484038));
    double[] distanceAlongShape = { 0.0, 405.7, 814.0 };
    List<PointAndIndex> assignments = spl.computePotentialAssignments(projectedShapePoints, distanceAlongShape, stopPoint, 0, 3);
    assertEquals(2, assignments.size());
    PointAndIndex assignment = assignments.get(0);
    assertEquals(398.9, assignment.distanceAlongShape, 0.1);
    assertEquals(39.6, assignment.distanceFromTarget, 0.1);
    assignment = assignments.get(1);
    assertEquals(445.4, assignment.distanceAlongShape, 0.1);
    assertEquals(6.2, assignment.distanceFromTarget, 0.1);
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) Test(org.junit.Test)

Example 2 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory 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 3 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory 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 4 with ShapePointsFactory

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

the class BlockConfigurationEntriesFactoryTest method before.

@Before
public void before() {
    /**
     **
     * Calendar Service
     ***
     */
    _calendarService = new CalendarServiceImpl();
    CalendarServiceData data = new CalendarServiceData();
    _calendarService.setData(data);
    addServiceDates(data, "sA", new ServiceDate(2010, 9, 10), new ServiceDate(2010, 9, 11));
    addServiceDates(data, "sB", new ServiceDate(2010, 9, 11), new ServiceDate(2010, 9, 12));
    /**
     **
     * Service Id Cache
     ***
     */
    ServiceIdOverlapCache serviceIdOverlapCache = new ServiceIdOverlapCache();
    serviceIdOverlapCache.setCalendarService(_calendarService);
    /**
     **
     * ShapePointsService
     ***
     */
    ShapePointHelper shapePointService = Mockito.mock(ShapePointHelper.class);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(0, 0);
    Mockito.when(shapePointService.getShapePointsForShapeId((AgencyAndId) Mockito.any())).thenReturn(shapePointsFactory.create());
    /**
     **
     * Factory
     ***
     */
    _factory = new BlockConfigurationEntriesFactory();
    _factory.setServiceIdOverlapCache(serviceIdOverlapCache);
    _factory.setShapePointHelper(shapePointService);
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) CalendarServiceImpl(org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl) ShapePointHelper(org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper) Before(org.junit.Before)

Example 5 with ShapePointsFactory

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

the class DistanceAlongShapeMain method readShapePoints.

private ShapePoints readShapePoints(String path) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(path));
    String line = null;
    ShapePointsFactory factory = new ShapePointsFactory();
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(" ");
        double lat = Double.parseDouble(tokens[0]);
        double lon = Double.parseDouble(tokens[1]);
        factory.addPoint(lat, lon);
    }
    reader.close();
    return factory.create();
}
Also used : ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)13 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)9 Test (org.junit.Test)8 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)8 Stop (org.onebusaway.gtfs.model.Stop)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)5 Agency (org.onebusaway.gtfs.model.Agency)4 Route (org.onebusaway.gtfs.model.Route)4 StopTime (org.onebusaway.gtfs.model.StopTime)4 Trip (org.onebusaway.gtfs.model.Trip)4 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)4 DistanceAlongShapeLibrary (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary)3 StopTimeEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory)3 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 BufferedReader (java.io.BufferedReader)2 Before (org.junit.Before)2 ShapePointHelper (org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2