Search in sources :

Example 66 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class StopForCodeAction method execute.

public String execute() throws Exception {
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_stopCode == null || _stopCode.length() == 0)
        return INPUT;
    SearchQueryBean searchQuery = new SearchQueryBean();
    searchQuery.setBounds(bounds);
    searchQuery.setMaxCount(5);
    searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    searchQuery.setQuery(_stopCode);
    StopsBean stopsBean = _transitDataService.getStops(searchQuery);
    _stops = stopsBean.getStops();
    if (_stops.size() == 0) {
        return "noStopsFound";
    } else if (_stops.size() == 1) {
        StopBean stop = _stops.get(0);
        _stopIds = Arrays.asList(stop.getId());
        return SUCCESS;
    } else {
        return "multipleStopsFound";
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 67 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class StopsBeanServiceImpl method getStopsByBoundsAndQuery.

private StopsBean getStopsByBoundsAndQuery(SearchQueryBean queryBean) throws ServiceException {
    CoordinateBounds bounds = queryBean.getBounds();
    String query = queryBean.getQuery();
    int maxCount = queryBean.getMaxCount();
    CoordinatePoint center = SphericalGeometryLibrary.getCenterOfBounds(bounds);
    SearchResult<AgencyAndId> stops;
    try {
        stops = _searchService.searchForStopsByCode(query, 10, MIN_SCORE);
    } catch (ParseException e) {
        throw new InvalidArgumentServiceException("query", "queryParseError");
    } catch (IOException e) {
        _log.error("error executing stop search: query=" + query, e);
        e.printStackTrace();
        throw new ServiceException();
    }
    Min<StopBean> closest = new Min<StopBean>();
    List<StopBean> stopBeans = new ArrayList<StopBean>();
    for (AgencyAndId aid : stops.getResults()) {
        StopBean stopBean = _stopBeanService.getStopForId(aid);
        if (bounds.contains(stopBean.getLat(), stopBean.getLon()))
            stopBeans.add(stopBean);
        double distance = SphericalGeometryLibrary.distance(center.getLat(), center.getLon(), stopBean.getLat(), stopBean.getLon());
        closest.add(distance, stopBean);
    }
    boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopBeans, maxCount);
    // If nothing was found in range, add the closest result
    if (stopBeans.isEmpty() && !closest.isEmpty())
        stopBeans.add(closest.getMinElement());
    return constructResult(stopBeans, limitExceeded);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Min(org.onebusaway.collections.Min) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) ParseException(org.apache.lucene.queryParser.ParseException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 68 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class CurrentVehicleEstimationServiceImpl method getBlockSequenceIndicesForRecords.

private Set<BlockSequenceIndex> getBlockSequenceIndicesForRecords(Map<Date, Record> recordsByTime) {
    Set<BlockSequenceIndex> allIndices = null;
    for (Record record : recordsByTime.values()) {
        CoordinateBounds bounds = SphericalGeometryLibrary.bounds(record.getLocation(), record.getAccuracy());
        Set<BlockSequenceIndex> indices = _blockGeospatialService.getBlockSequenceIndexPassingThroughBounds(bounds);
        if (allIndices == null)
            allIndices = indices;
        else
            allIndices.retainAll(indices);
    }
    return allIndices;
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 69 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class RoutesBeanServiceImpl method getRoutesWithoutRouteNameQuery.

/**
 **
 * Private Methods
 ***
 */
private RoutesBean getRoutesWithoutRouteNameQuery(SearchQueryBean query) {
    CoordinateBounds bounds = query.getBounds();
    List<AgencyAndId> stops = _whereGeospatialService.getStopsByBounds(bounds);
    Set<RouteBean> routes = new HashSet<RouteBean>();
    for (AgencyAndId stopId : stops) {
        StopBean stop = _stopService.getStopForId(stopId);
        routes.addAll(stop.getRoutes());
    }
    List<RouteBean> routeBeans = new ArrayList<RouteBean>(routes);
    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) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) HashSet(java.util.HashSet)

Example 70 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class TransitDataServiceTemplateImpl method getAgencyIdsWithCoverageArea.

/**
 **
 * {@link TransitDataService} Interface
 ***
 */
// @Override
public Map<String, List<CoordinateBounds>> getAgencyIdsWithCoverageArea() {
    Map<String, CoordinateBounds> agencyIdsAndCoverageAreas = _agencyService.getAgencyIdsAndCoverageAreas();
    Map<String, List<CoordinateBounds>> result = new HashMap<String, List<CoordinateBounds>>();
    for (Map.Entry<String, CoordinateBounds> entry : agencyIdsAndCoverageAreas.entrySet()) {
        String agencyId = entry.getKey();
        CoordinateBounds bounds = entry.getValue();
        List<CoordinateBounds> coverage = Arrays.asList(bounds);
        result.put(agencyId, coverage);
    }
    return result;
}
Also used : 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