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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations