Search in sources :

Example 41 with CoordinateBounds

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

Example 42 with CoordinateBounds

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";
    }
}
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 43 with CoordinateBounds

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

Example 44 with CoordinateBounds

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();
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 45 with CoordinateBounds

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));
    }
}
Also used : OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

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