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;
}
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));
}
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());
}
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());
}
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);
}
Aggregations