Search in sources :

Example 1 with CoordinateBounds

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";
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 2 with CoordinateBounds

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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 3 with CoordinateBounds

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();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) STRtree(com.vividsolutions.jts.index.strtree.STRtree) List(java.util.List) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 4 with CoordinateBounds

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 5 with CoordinateBounds

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);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) STRtree(com.vividsolutions.jts.index.strtree.STRtree) Envelope(com.vividsolutions.jts.geom.Envelope) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

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