use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImplTest method testGetStopsForRoute.
@Test
public void testGetStopsForRoute() {
AgencyAndId routeId = new AgencyAndId("1", "route");
RouteEntryImpl route = new RouteEntryImpl();
route.setId(new AgencyAndId("1", "raw_route"));
List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
routeCollection.setId(routeId);
routeCollection.setChildren(routes);
route.setParent(routeCollection);
Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidA");
tripA.setRoute(route);
tripA.setDirectionId("0");
tripB.setRoute(route);
tripB.setDirectionId("1");
route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
TripNarrative.Builder tnA = TripNarrative.builder();
tnA.setTripHeadsign("Destination A");
Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
TripNarrative.Builder tnB = TripNarrative.builder();
tnB.setTripHeadsign("Destination B");
Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
linkBlockTrips(blockA, tripA, tripB);
List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
StopBean stopBeanA = getStopBean(stopA);
StopBean stopBeanB = getStopBean(stopB);
StopBean stopBeanC = getStopBean(stopC);
List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
shapeIds.add(shapeId);
tripA.setShapeId(shapeId);
EncodedPolylineBean polyline = new EncodedPolylineBean();
Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
// Setup complete
StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
List<StopBean> stops = stopsForRoute.getStops();
assertEquals(3, stops.size());
assertSame(stopBeanA, stops.get(0));
assertSame(stopBeanB, stops.get(1));
assertSame(stopBeanC, stops.get(2));
List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
assertEquals(1, polylines.size());
assertSame(polyline, polylines.get(0));
List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
assertEquals(1, groupings.size());
StopGroupingBean grouping = groupings.get(0);
assertEquals("direction", grouping.getType());
List<StopGroupBean> groups = grouping.getStopGroups();
assertEquals(2, groups.size());
StopGroupBean groupA = groups.get(0);
StopGroupBean groupB = groups.get(1);
NameBean nameA = groupA.getName();
assertEquals("destination", nameA.getType());
assertEquals("Destination A", nameA.getName());
List<String> stopIdsA = groupA.getStopIds();
assertEquals(3, stopIdsA.size());
assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
NameBean nameB = groupB.getName();
assertEquals("destination", nameB.getType());
assertEquals("Destination B", nameB.getName());
List<String> stopIdsB = groupB.getStopIds();
assertEquals(2, stopIdsB.size());
assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.
the class PolylineEncoderTest method test4.
@Test
public void test4() {
double[] lat = { 47.3, 47.67839087880088, 47.67845871865856, 47.682076843204875, 47.4 };
double[] lon = { -122.3, -122.27878118907307, -122.27342376951559, -122.2735240417865, -122.4 };
String expected = "}d_bHlqiiVKo`@sUR";
EncodedPolylineBean actual = PolylineEncoder.createEncodings(lat, lon, 1, 3, 0);
Assert.assertEquals(expected, actual.getPoints());
}
use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.
the class PolylineEncoderTest method testEncoder.
@Test
public void testEncoder() {
List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
points.add(new CoordinatePoint(38.5, -120.2));
points.add(new CoordinatePoint(40.7, -120.95));
points.add(new CoordinatePoint(43.252, -126.453));
String expected = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
EncodedPolylineBean actual = PolylineEncoder.createEncodings(points, 0);
Assert.assertEquals(expected, actual.getPoints());
List<CoordinatePoint> decodedPoints = PolylineEncoder.decode(actual);
GeospatialTestSupport.assertEqualsPointLists(points, decodedPoints, 1e-5);
}
use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.
the class PolylineEncoder method createEncodings.
/**
* If level < 0, then {@link EncodedPolylineBean#getLevels()} will be null.
*
* @param points
* @param level
* @return
*/
public static EncodedPolylineBean createEncodings(Iterable<CoordinatePoint> points, int level) {
StringBuilder encodedPoints = new StringBuilder();
StringBuilder encodedLevels = new StringBuilder();
int plat = 0;
int plng = 0;
int count = 0;
for (CoordinatePoint trackpoint : points) {
int late5 = floor1e5(trackpoint.getLat());
int lnge5 = floor1e5(trackpoint.getLon());
int dlat = late5 - plat;
int dlng = lnge5 - plng;
plat = late5;
plng = lnge5;
encodedPoints.append(encodeSignedNumber(dlat)).append(encodeSignedNumber(dlng));
if (level >= 0)
encodedLevels.append(encodeNumber(level));
count++;
}
String pointsString = encodedPoints.toString();
String levelsString = level >= 0 ? encodedLevels.toString() : null;
return new EncodedPolylineBean(pointsString, levelsString, count);
}
use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImpl method getStopResult.
@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
for (RouteBean routeBean : stopBean.getRoutes()) {
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
List<RouteDirection> directions = new ArrayList<RouteDirection>();
List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
for (StopGroupingBean stopGroupingBean : stopGroupings) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
NameBean name = stopGroupBean.getName();
String type = name.getType();
if (!type.equals("destination"))
continue;
List<String> polylines = new ArrayList<String>();
for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
polylines.add(polyline.getPoints());
}
Boolean hasUpcomingScheduledService = null;
// We do this to prevent checking if there is service in a direction that does not even serve this stop.
if (stopGroupBean.getStopIds().contains(stopBean.getId())) {
hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
// if there are buses on route, always have "scheduled service"
Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForStopAndRoute(stopBean.getId(), routeBean.getId(), SystemTime.currentTimeMillis());
if (routeHasVehiclesInService) {
hasUpcomingScheduledService = true;
}
}
directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
}
}
RouteAtStop routeAtStop = new RouteAtStop(routeBean, directions);
routesAtStop.add(routeAtStop);
}
return new StopResult(stopBean, routesAtStop);
}
Aggregations