use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class NearbyStopsBeanServiceImplTest method test.
@Test
public void test() {
AgencyAndId stopIdA = new AgencyAndId("1", "stopA");
AgencyAndId stopIdB = new AgencyAndId("1", "stopB");
StopBean stop = new StopBean();
stop.setId(AgencyAndIdLibrary.convertToString(stopIdA));
stop.setLat(47.0);
stop.setLon(-122.0);
List<AgencyAndId> stopIds = new ArrayList<AgencyAndId>();
stopIds.add(stopIdA);
stopIds.add(stopIdB);
CoordinateBounds bounds = SphericalGeometryLibrary.bounds(stop.getLat(), stop.getLon(), 400);
Mockito.when(_geoBeanService.getStopsByBounds(bounds)).thenReturn(stopIds);
List<AgencyAndId> nearby = _service.getNearbyStops(stop, 400);
assertEquals(1, nearby.size());
assertTrue(nearby.contains(stopIdB));
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class RouteForNameAction method execute.
public String execute() throws Exception {
_log.debug("in RouteForName with routeName " + _routeName);
CoordinateBounds bounds = getDefaultSearchArea();
if (bounds == null) {
return NEEDS_DEFAULT_SEARCH_LOCATION;
}
if (_routeName == null || _routeName.length() == 0) {
return INPUT;
}
SearchQueryBean routesQuery = new SearchQueryBean();
routesQuery.setBounds(bounds);
routesQuery.setMaxCount(10);
routesQuery.setQuery(_routeName);
routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
RoutesBean routesBean = _transitDataService.getRoutes(routesQuery);
List<RouteBean> routes = routesBean.getRoutes();
sessionMap.put("navState", new Integer(DISPLAY_DATA));
logUserInteraction("route", _routeName);
if (routes.size() == 0) {
sessionMap.put("messageFromAction", getText(Messages.NO_ROUTES_WERE_FOUND));
sessionMap.put("backAction", "search-index");
return "noRoutesFound";
} else if (routes.size() == 1) {
_route = routes.get(0);
return SUCCESS;
} else {
_routes = routes;
return "multipleRoutesFound";
}
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class MonitoringActionBase method isValidBoundsDistance.
protected boolean isValidBoundsDistance(CoordinateBounds bounds, double maxRadius) {
if (bounds != null) {
CoordinateBounds maxBounds = SphericalGeometryLibrary.bounds(bounds.getMinLat(), bounds.getMinLon(), maxRadius + 1);
double maxLatSpan = (maxBounds.getMaxLat() - maxBounds.getMinLat());
double maxLonSpan = (maxBounds.getMaxLon() - maxBounds.getMinLon());
double latSpan = (bounds.getMaxLat() - bounds.getMinLat());
double lonSpan = (bounds.getMaxLon() - bounds.getMinLon());
if (latSpan < maxLatSpan && lonSpan < maxLonSpan) {
return true;
}
}
return false;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class StopsForLocationAction method index.
public DefaultHttpHeaders index() throws IOException, ServiceException {
int maxCount = _maxCount.getMaxCount();
if (maxCount <= 0)
addFieldError("maxCount", "must be greater than zero");
if (hasErrors())
return setValidationErrorsResponse();
CoordinateBounds bounds = getSearchBounds();
SearchQueryBean searchQuery = new SearchQueryBean();
searchQuery.setBounds(bounds);
searchQuery.setMaxCount(maxCount);
searchQuery.setType(EQueryType.BOUNDS);
if (_query != null) {
searchQuery.setQuery(_query);
searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
}
try {
StopsBean result = _service.getStops(searchQuery);
return transformResult(result);
} catch (OutOfServiceAreaServiceException ex) {
return transformOutOfRangeResult();
}
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class TripsForLocationAction method index.
public DefaultHttpHeaders index() throws IOException, ServiceException {
if (!isVersion(V2))
return setUnknownVersionResponse();
if (hasErrors())
return setValidationErrorsResponse();
CoordinateBounds bounds = _searchBoundsFactory.createBounds();
long time = SystemTime.currentTimeMillis();
if (_time != 0)
time = _time;
TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
query.setBounds(bounds);
query.setTime(time);
query.setMaxCount(_maxCount.getMaxCount());
TripDetailsInclusionBean inclusion = query.getInclusion();
inclusion.setIncludeTripBean(_includeTrip);
inclusion.setIncludeTripSchedule(_includeSchedule);
inclusion.setIncludeTripStatus(_includeStatus);
BeanFactoryV2 factory = getBeanFactoryV2();
try {
ListBean<TripDetailsBean> trips = _service.getTripsForBounds(query);
return setOkResponse(factory.getTripDetailsResponse(trips));
} catch (OutOfServiceAreaServiceException ex) {
return setOkResponse(factory.getEmptyList(TripDetailsV2Bean.class, true));
}
}
Aggregations