Search in sources :

Example 6 with AgencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry 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;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 7 with AgencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry in project onebusaway-application-modules by camsys.

the class StopsBeanServiceImpl method getStopsIdsForAgencyId.

@Override
public ListBean<String> getStopsIdsForAgencyId(String agencyId) {
    AgencyEntry agency = _transitGraphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<String> ids = new ArrayList<String>();
    for (StopEntry stop : agency.getStops()) {
        AgencyAndId id = stop.getId();
        ids.add(AgencyAndIdLibrary.convertToString(id));
    }
    return new ListBean<String>(ids, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)

Example 8 with AgencyEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry in project onebusaway-application-modules by camsys.

the class RoutesBeanServiceImpl method getRouteIdsForAgencyId.

@Cacheable
@Override
public ListBean<String> getRouteIdsForAgencyId(String agencyId) {
    AgencyEntry agency = _graphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<String> ids = new ArrayList<String>();
    for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
        AgencyAndId id = routeCollection.getId();
        ids.add(AgencyAndIdLibrary.convertToString(id));
    }
    return new ListBean<String>(ids, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Aggregations

AgencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)8 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)5 ArrayList (java.util.ArrayList)4 Cacheable (org.onebusaway.container.cache.Cacheable)4 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 ListBean (org.onebusaway.transit_data.model.ListBean)3 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 HashMap (java.util.HashMap)2 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 Test (org.junit.Test)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 Agency (org.onebusaway.gtfs.model.Agency)1 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)1 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)1