Search in sources :

Example 31 with CoordinateBounds

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

the class FederatedByCoordinateBoundsMethodInvocationHandlerImplTest method test01.

@Test
public void test01() throws Exception {
    CoordinateBounds bounds = new CoordinateBounds(0, 1, 2, 3);
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForBounds(bounds)).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForCoordinateBounds", CoordinateBounds.class);
    Object[] args = { bounds };
    FederatedServiceMethodInvocationHandler handler = new FederatedByCoordinateBoundsMethodInvocationHandlerImpl(method, 0, "");
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForCoordinateBounds(bounds);
}
Also used : 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 32 with CoordinateBounds

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

the class SphericalGeometryLibrary method bounds.

public static CoordinateBounds bounds(CoordinateBounds b, double distance) {
    CoordinateBounds b2 = bounds(b.getMinLat(), b.getMinLon(), distance);
    CoordinateBounds b3 = bounds(b.getMaxLat(), b.getMaxLon(), distance);
    b2.addBounds(b3);
    return b2;
}
Also used : CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 33 with CoordinateBounds

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

the class SphericalGeometryLibrary method getOrientation.

/**
 * If Wikipedia is to be trusted, then:
 *
 * http://en.wikipedia.org/wiki/Spherical_law_of_cosines
 *
 * claims that the standard ordinary planar law of cosines is a reasonable
 * approximation for the more-complex spherical law of cosines when the
 * central angles of the spherical triangle are small.
 *
 * @param latFrom
 * @param lonFrom
 * @param latTo
 * @param lonTo
 * @return the orientation angle in degrees, 0º is East, 90º is North, 180º is
 *         West, and 270º is South
 */
public static double getOrientation(double latFrom, double lonFrom, double latTo, double lonTo) {
    double d = distance(latFrom, lonFrom, latTo, lonTo);
    CoordinateBounds bounds = bounds(latFrom, lonFrom, d);
    XYPoint origin = new XYPoint(lonFrom, latFrom);
    XYPoint axis = new XYPoint(bounds.getMaxLon(), latFrom);
    XYPoint target = new XYPoint(lonTo, latTo);
    double angle = GeometryLibrary.getAngle(origin, axis, target);
    if (latTo < latFrom)
        angle = 2 * Math.PI - angle;
    return Math.toDegrees(angle);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 34 with CoordinateBounds

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

the class HierarchicalSTRtreeFactory method add.

public void add(double lat, double lon, T element) {
    STRtree tree = null;
    for (Map.Entry<CoordinateBounds, STRtree> entry : _treesByBounds.entrySet()) {
        CoordinateBounds bounds = entry.getKey();
        if (bounds.contains(lat, lon)) {
            tree = entry.getValue();
            break;
        }
    }
    if (tree == null) {
        double gLat = Math.floor(lat / _latStep) * _latStep;
        double gLon = Math.floor(lon / _lonStep) * _lonStep;
        CoordinateBounds b = new CoordinateBounds(gLat, gLon, gLat + _latStep, gLon + _lonStep);
        tree = new STRtree();
        _treesByBounds.put(b, tree);
    }
    Envelope env = new Envelope(lon, lon, lat, lat);
    tree.insert(env, element);
}
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 35 with CoordinateBounds

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

the class AgencyServiceImpl method getAgencyIdsAndCoverageAreas.

@Cacheable
public Map<String, CoordinateBounds> getAgencyIdsAndCoverageAreas() {
    Map<String, CoordinateBounds> boundsByAgencyId = new HashMap<String, CoordinateBounds>();
    for (AgencyEntry agency : _graph.getAllAgencies()) {
        CoordinateBounds bounds = new CoordinateBounds();
        for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
            for (RouteEntry route : routeCollection.getChildren()) {
                for (TripEntry trip : route.getTrips()) {
                    for (StopTimeEntry stopTime : trip.getStopTimes()) {
                        StopEntry stop = stopTime.getStop();
                        bounds.addPoint(stop.getStopLat(), stop.getStopLon());
                    }
                }
            }
        }
        boundsByAgencyId.put(agency.getId(), bounds);
    }
    return boundsByAgencyId;
}
Also used : 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) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

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