Search in sources :

Example 46 with CoordinateBounds

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

the class DynamicFederatedServiceCollectionImplTest method addServiceServlet.

private SimpleFederatedServiceImpl addServiceServlet(Server server, String agencyId, CoordinateBounds bounds) {
    Map<String, List<CoordinateBounds>> agenciesA = new HashMap<String, List<CoordinateBounds>>();
    agenciesA.put(agencyId, Arrays.asList(bounds));
    SimpleFederatedServiceImpl serviceA = new SimpleFederatedServiceImpl(agenciesA, agencyId);
    HessianServlet servletA = new HessianServlet();
    servletA.setHome(serviceA);
    servletA.setHomeAPI(SimpleFederatedService.class);
    Context contextA = new Context(server, "/service-" + agencyId, Context.SESSIONS);
    contextA.addServlet(new ServletHolder(servletA), "/*");
    return serviceA;
}
Also used : Context(org.mortbay.jetty.servlet.Context) HashMap(java.util.HashMap) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) List(java.util.List) HessianServlet(com.caucho.hessian.server.HessianServlet) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 47 with CoordinateBounds

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

the class FederatedServiceLibrary method checkAgencyAndCoverageAgainstExisting.

/**
 * Given an existing set of {@link FederatedService} instances along with
 * their set of agency ids and geographic bounds, examine an additional agency
 * id and coverage area from another service instance and verify that there is
 * no overlap.
 *
 * @param byProvider existing {@link FederatedService} instances along with
 *          their agency ids and coverage areas
 * @param agencyId a new agency id to check
 * @param coverage the coverage area for that agency
 * @param serviceInterface the target service interface
 * @param failHard throw an exception if overlap is found
 * @return true if there is no overlap (good), other false (bad)
 */
public static boolean checkAgencyAndCoverageAgainstExisting(Map<FederatedService, Map<String, List<CoordinateBounds>>> byProvider, String agencyId, List<CoordinateBounds> coverage, Class<?> serviceInterface, boolean failHard) {
    for (Map<String, List<CoordinateBounds>> other : byProvider.values()) {
        // elsewhere
        if (other.containsKey(agencyId)) {
            if (failHard)
                throw new IllegalArgumentException("agency \"" + agencyId + "\" is handled by multiple providers for service " + serviceInterface.getName());
            else
                return false;
        }
        // another provider
        for (Map.Entry<String, List<CoordinateBounds>> otherEntry : other.entrySet()) {
            String otherAgencyId = otherEntry.getKey();
            List<CoordinateBounds> otherCoverage = otherEntry.getValue();
            for (CoordinateBounds otherRectangle : otherCoverage) {
                for (CoordinateBounds rectangle : coverage) {
                    if (rectangle.intersects(otherRectangle)) {
                        if (failHard)
                            throw new IllegalArgumentException("agency \"" + agencyId + "\" has overlap with agency \"" + otherAgencyId + "\" in separate service providers of type " + serviceInterface.getName());
                        else
                            return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 48 with CoordinateBounds

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

the class FederatedByCoordinateBoundsMethodInvocationHandlerImplTest method test02.

@Test
public void test02() throws Exception {
    CoordinateBounds bounds = new CoordinateBounds(0, 1, 2, 3);
    CoordinateBoundsTestBean bean = new CoordinateBoundsTestBean();
    bean.setBounds(bounds);
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForBounds(bounds)).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForCoordinateBoundsTestBean", CoordinateBoundsTestBean.class);
    Object[] args = { bean };
    FederatedServiceMethodInvocationHandler handler = new FederatedByCoordinateBoundsMethodInvocationHandlerImpl(method, 0, "bounds");
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForCoordinateBoundsTestBean(bean);
}
Also used : CoordinateBoundsTestBean(org.onebusaway.federations.CoordinateBoundsTestBean) FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 49 with CoordinateBounds

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

the class HierarchicalSTRtreeFactory method create.

public HierarchicalSTRtree<T> create() {
    STRtree parentTree = new STRtree();
    for (Map.Entry<CoordinateBounds, STRtree> entry : _treesByBounds.entrySet()) {
        CoordinateBounds b = entry.getKey();
        Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
        STRtree tree = entry.getValue();
        tree.build();
        parentTree.insert(env, tree);
    }
    parentTree.build();
    return new HierarchicalSTRtree<T>(parentTree);
}
Also used : STRtree(com.vividsolutions.jts.index.strtree.STRtree) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 50 with CoordinateBounds

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

the class HierarchicalSTRtreeFactory method setLatAndLonStep.

public void setLatAndLonStep(double lat, double lon, double gridSize) {
    CoordinateBounds b = SphericalGeometryLibrary.bounds(lat, lon, gridSize / 2);
    _latStep = b.getMaxLat() - b.getMinLat();
    _lonStep = b.getMaxLon() - b.getMinLon();
}
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