Search in sources :

Example 21 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class FederatedServiceLibrary method getFederatedServiceAgencyCoverage.

/**
 * Given a list of {@link FederatedService} instances {@code
 * federatedServiceInstances} that implement a target {@code
 * federatedServiceInterface}, query each instance in turn to determine its
 * set of agencies and geographic bounds, verifying that no two distinct
 * federated service instances have overlapping agency ids or geographic
 * bounds. We construct a map from each service instance to its set of agency
 * ids along with their geographic regions.
 *
 * @param federatedServiceInstances
 * @param federatedServiceInterface
 * @return a map of service instances along with their agency ids and coverage
 *         areas
 */
public static Map<FederatedService, Map<String, List<CoordinateBounds>>> getFederatedServiceAgencyCoverage(List<? extends FederatedService> federatedServiceInstances, Class<? extends FederatedService> federatedServiceInterface) {
    Map<FederatedService, Map<String, List<CoordinateBounds>>> byProvider = new HashMap<FederatedService, Map<String, List<CoordinateBounds>>>();
    for (FederatedService service : federatedServiceInstances) {
        if (!federatedServiceInterface.isAssignableFrom(service.getClass()))
            throw new IllegalArgumentException("service provider " + service + " not instance of " + federatedServiceInterface.getName());
        Map<String, List<CoordinateBounds>> agencyIdsWithCoverageArea = service.getAgencyIdsWithCoverageArea();
        for (Map.Entry<String, List<CoordinateBounds>> entry : agencyIdsWithCoverageArea.entrySet()) {
            String agencyId = entry.getKey();
            List<CoordinateBounds> coverage = entry.getValue();
            checkAgencyAndCoverageAgainstExisting(byProvider, agencyId, coverage, federatedServiceInterface, true);
        }
        byProvider.put(service, agencyIdsWithCoverageArea);
    }
    return byProvider;
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) HashMap(java.util.HashMap) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 22 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class SearchServiceImpl method findRoutesStoppingNearPoint.

@Override
public SearchResultCollection findRoutesStoppingNearPoint(Double latitude, Double longitude, SearchResultFactory resultFactory) {
    CoordinateBounds bounds = SphericalGeometryLibrary.bounds(latitude, longitude, DISTANCE_TO_ROUTES);
    SearchResultCollection results = new SearchResultCollection();
    SearchQueryBean queryBean = new SearchQueryBean();
    queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
    queryBean.setBounds(bounds);
    queryBean.setMaxCount(100);
    RoutesBean routes = null;
    try {
        routes = _transitDataService.getRoutes(queryBean);
    } catch (OutOfServiceAreaServiceException e) {
        return results;
    }
    Collections.sort(routes.getRoutes(), new RouteDistanceFromPointComparator(latitude, longitude));
    for (RouteBean route : routes.getRoutes()) {
        SearchResult result = resultFactory.getRouteResult(route);
        results.addMatch(result);
        if (results.getMatches().size() > MAX_ROUTES) {
            break;
        }
    }
    return results;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) SearchResultCollection(org.onebusaway.presentation.model.SearchResultCollection) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) SearchResult(org.onebusaway.presentation.model.SearchResult) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 23 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class WhereGeospatialServiceImplTest method test.

@Test
public void test() {
    WhereGeospatialServiceImpl service = new WhereGeospatialServiceImpl();
    TransitGraphDao dao = Mockito.mock(TransitGraphDao.class);
    service.setTransitGraphDao(dao);
    StopEntry stopA = stop("a", -0.5, -0.5);
    StopEntry stopB = stop("b", -0.5, 0.5);
    StopEntry stopC = stop("c", 0.5, -0.5);
    StopEntry stopD = stop("d", 0.5, 0.5);
    List<StopEntry> allStops = Arrays.asList(stopA, stopB, stopC, stopD);
    Mockito.when(dao.getAllStops()).thenReturn(allStops);
    service.initialize();
    List<AgencyAndId> stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 0, 0));
    assertEquals(1, stops.size());
    assertTrue(stops.contains(stopA.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(0, -1, 1, 0));
    assertEquals(1, stops.size());
    assertTrue(stops.contains(stopC.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 0));
    assertEquals(2, stops.size());
    assertTrue(stops.contains(stopA.getId()));
    assertTrue(stops.contains(stopC.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 1));
    assertEquals(4, stops.size());
    assertTrue(stops.contains(stopA.getId()));
    assertTrue(stops.contains(stopB.getId()));
    assertTrue(stops.contains(stopC.getId()));
    assertTrue(stops.contains(stopD.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(0.8, 0.8, 1, 1));
    assertEquals(0, stops.size());
}
Also used : TransitGraphDao(org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 24 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class DynamicFederatedServiceCollectionImplTest method start.

@Before
public void start() throws Exception {
    _server = new Server(PORT);
    addServiceServlet(_server, "A", new CoordinateBounds(0, 0, 10, 10));
    addServiceServlet(_server, "B", new CoordinateBounds(20, 20, 30, 30));
    Map<String, List<CoordinateBounds>> agenciesB = new HashMap<String, List<CoordinateBounds>>();
    agenciesB.put("B", Arrays.asList(new CoordinateBounds(30, 30, 40, 40)));
    _server.start();
    _registry = new FederatedServiceRegistryImpl();
    _collection = new DynamicFederatedServiceCollectionImpl();
    _collection.setRegistry(_registry);
    _collection.setUpdateFrequency(1);
    _collection.setServiceInterface(SimpleFederatedService.class);
    _collection.start();
}
Also used : Server(org.mortbay.jetty.Server) HashMap(java.util.HashMap) List(java.util.List) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Before(org.junit.Before)

Example 25 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class EnterpriseGoogleGeocoderResult method isRegion.

public boolean isRegion() {
    CoordinateBounds bounds = getBounds();
    if (bounds != null) {
        double height = SphericalGeometryLibrary.distanceFaster(bounds.getMaxLat(), bounds.getMinLon(), bounds.getMinLat(), bounds.getMinLon());
        double width = SphericalGeometryLibrary.distanceFaster(bounds.getMinLat(), bounds.getMinLon(), bounds.getMinLat(), bounds.getMaxLon());
        double area = width * height;
        // region must be larger than 1200 x 1200 meters
        if (area > 1440000)
            return true;
    }
    return false;
}
Also used : CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)70 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 List (java.util.List)14 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)12 Map (java.util.Map)9 StopBean (org.onebusaway.transit_data.model.StopBean)9 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 RouteBean (org.onebusaway.transit_data.model.RouteBean)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 Envelope (com.vividsolutions.jts.geom.Envelope)5 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)5 STRtree (com.vividsolutions.jts.index.strtree.STRtree)4 File (java.io.File)4 IOException (java.io.IOException)4 Filters (org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters)4 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)4 RoutesBean (org.onebusaway.transit_data.model.RoutesBean)4