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