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