use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry in project onebusaway-application-modules by camsys.
the class GtfsController method getStops.
@RequestMapping(value = "/stops/{agencyId}/{id}")
@ResponseBody
public List<CoordinatePoint> getStops(@PathVariable String agencyId, @PathVariable String id) {
AgencyAndId routeId = new AgencyAndId(agencyId, id);
RouteEntry route = _transitGraphDao.getRouteForId(routeId);
TripEntry trip = routeToTrip(route);
List<StopTimeEntry> stopTimes = trip.getStopTimes();
List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
for (StopTimeEntry entry : stopTimes) {
StopEntry stop = entry.getStop();
points.add(stop.getStopLocation());
}
return points;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactory method createRouteShortNameRouteCollectionMapping.
private void createRouteShortNameRouteCollectionMapping(TransitGraphImpl graph) {
Map<AgencyAndId, List<RouteEntryImpl>> routesByKey = new HashMap<AgencyAndId, List<RouteEntryImpl>>();
for (RouteEntryImpl routeEntry : graph.getRoutes()) {
Route route = _gtfsDao.getRouteForId(routeEntry.getId());
AgencyAndId key = getRouteCollectionIdForRoute(route);
List<RouteEntryImpl> forKey = routesByKey.get(key);
if (forKey == null) {
forKey = new ArrayList<RouteEntryImpl>();
routesByKey.put(key, forKey);
}
forKey.add(routeEntry);
}
for (Map.Entry<AgencyAndId, List<RouteEntryImpl>> entry : routesByKey.entrySet()) {
AgencyAndId key = entry.getKey();
List<RouteEntryImpl> routesForKey = entry.getValue();
ArrayList<RouteEntry> children = new ArrayList<RouteEntry>();
children.addAll(routesForKey);
children.trimToSize();
key = _uniqueService.unique(key);
RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
routeCollectionEntry.setId(key);
routeCollectionEntry.setChildren(children);
graph.putRouteCollectionEntry(routeCollectionEntry);
for (RouteEntryImpl route : routesForKey) route.setParent(routeCollectionEntry);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactory method createOneToOneRouteCollectionMapping.
private void createOneToOneRouteCollectionMapping(TransitGraphImpl graph) {
for (RouteEntryImpl routeEntry : graph.getRoutes()) {
RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
routeCollectionEntry.setId(routeEntry.getId());
ArrayList<RouteEntry> routes = new ArrayList<RouteEntry>();
routes.add(routeEntry);
routes.trimToSize();
routeCollectionEntry.setChildren(routes);
graph.putRouteCollectionEntry(routeCollectionEntry);
routeEntry.setParent(routeCollectionEntry);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry in project onebusaway-application-modules by camsys.
the class RouteEntriesFactoryTest method testProcessRoutes.
@Test
public void testProcessRoutes() {
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
Agency agency = new Agency();
agency.setId("A");
Route routeA = new Route();
routeA.setAgency(agency);
routeA.setId(new AgencyAndId("A", "routeA"));
Route routeB = new Route();
routeB.setAgency(agency);
routeB.setId(new AgencyAndId("A", "routeB"));
Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(routeA, routeB));
TransitGraphImpl graph = new TransitGraphImpl();
RouteEntriesFactory factory = new RouteEntriesFactory();
factory.setGtfsDao(gtfsDao);
factory.setUniqueService(new UniqueServiceImpl());
factory.processRoutes(graph);
RouteEntryImpl routeEntryA = graph.getRouteForId(routeA.getId());
RouteEntryImpl routeEntryB = graph.getRouteForId(routeB.getId());
List<RouteEntry> routes = graph.getAllRoutes();
assertEquals(2, routes.size());
assertTrue(routes.contains(routeEntryA));
assertTrue(routes.contains(routeEntryB));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry in project onebusaway-application-modules by camsys.
the class AgencyServiceImpl method getAgencyIdsAndCenterPoints.
@Cacheable
public Map<String, CoordinatePoint> getAgencyIdsAndCenterPoints() {
Map<String, CoordinatePoint> centersByAgencyId = new HashMap<String, CoordinatePoint>();
for (AgencyEntry agency : _graph.getAllAgencies()) {
StopsCenterOfMass centerOfMass = new StopsCenterOfMass();
for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
for (RouteEntry route : routeCollection.getChildren()) {
for (TripEntry trip : route.getTrips()) {
for (StopTimeEntry stopTime : trip.getStopTimes()) {
StopEntry stop = stopTime.getStop();
centerOfMass.lats += stop.getStopLat();
centerOfMass.lons += stop.getStopLon();
centerOfMass.count++;
}
}
}
}
if (centerOfMass.count == 0) {
_log.warn("Agency has no service: " + agency);
} else {
double lat = centerOfMass.lats / centerOfMass.count;
double lon = centerOfMass.lons / centerOfMass.count;
centersByAgencyId.put(agency.getId(), new CoordinatePoint(lat, lon));
}
}
return centersByAgencyId;
}
Aggregations