use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class RouteForNameAction method execute.
@Override
public String execute() throws Exception {
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();
if (routes.size() == 0) {
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 StopsBeanServiceImpl method getStopsByBounds.
private StopsBean getStopsByBounds(SearchQueryBean queryBean) throws ServiceException {
CoordinateBounds bounds = queryBean.getBounds();
List<AgencyAndId> stopIds = _geospatialBeanService.getStopsByBounds(bounds);
boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopIds, queryBean.getMaxCount());
List<StopBean> stopBeans = new ArrayList<StopBean>();
for (AgencyAndId stopId : stopIds) {
StopBean stopBean = _stopBeanService.getStopForId(stopId);
if (stopBean == null)
throw new ServiceException();
/**
* If the stop doesn't have any routes actively serving it, don't include
* it in the results
*/
if (stopBean.getRoutes().isEmpty())
continue;
stopBeans.add(stopBean);
}
return constructResult(stopBeans, limitExceeded);
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class BlockGeospatialServiceImpl method buildShapeSpatialIndex.
private void buildShapeSpatialIndex() throws IOException, ClassNotFoundException {
File path = _bundle.getShapeGeospatialIndexDataPath();
if (!path.exists()) {
_tree = null;
return;
}
_log.info("loading shape point geospatial index...");
Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByGridCell = ObjectSerializationLibrary.readObject(path);
_log.info("block shape geospatial nodes: " + shapeIdsByGridCell.size());
if (shapeIdsByGridCell.isEmpty()) {
_tree = null;
return;
}
_tree = new STRtree(shapeIdsByGridCell.size());
for (Map.Entry<CoordinateBounds, List<AgencyAndId>> entry : shapeIdsByGridCell.entrySet()) {
CoordinateBounds b = entry.getKey();
Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
List<AgencyAndId> shapeIds = entry.getValue();
_tree.insert(env, shapeIds);
}
_tree.build();
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class NearbyStopsBeanServiceImpl method getNearbyStops.
@Cacheable
public List<AgencyAndId> getNearbyStops(@CacheableArgument(keyProperty = "id") StopBean stopBean, double radius) {
CoordinateBounds bounds = SphericalGeometryLibrary.bounds(stopBean.getLat(), stopBean.getLon(), radius);
List<AgencyAndId> ids = _geospatialBeanService.getStopsByBounds(bounds);
List<AgencyAndId> excludingSource = new ArrayList<AgencyAndId>();
for (AgencyAndId id : ids) {
if (!ApplicationBeanLibrary.getId(id).equals(stopBean.getId()))
excludingSource.add(id);
}
return excludingSource;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class RoutesBeanServiceImpl method getRoutesWithRouteNameQuery.
private RoutesBean getRoutesWithRouteNameQuery(SearchQueryBean query) throws ServiceException {
SearchResult<AgencyAndId> result = searchForRoutes(query);
List<RouteBean> routeBeans = new ArrayList<RouteBean>();
CoordinateBounds bounds = query.getBounds();
for (AgencyAndId id : result.getResults()) {
STRtree tree = _stopTreesByRouteId.get(id);
if (tree == null) {
_log.warn("stop tree not found for routeId=" + id);
continue;
}
Envelope env = new Envelope(bounds.getMinLon(), bounds.getMaxLon(), bounds.getMinLat(), bounds.getMaxLat());
HasItemsVisitor v = new HasItemsVisitor();
tree.query(env, v);
if (v.hasItems()) {
RouteBean routeBean = _routeBeanService.getRouteForId(id);
routeBeans.add(routeBean);
}
}
boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(routeBeans, query.getMaxCount());
return constructResult(routeBeans, limitExceeded);
}
Aggregations