private SearchQueryBean makeSearchQuery(String q, CoordinateBounds bounds) { SearchQueryBean queryBean = new SearchQueryBean(); queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST); queryBean.setBounds(bounds); queryBean.setMaxCount(5); if (q != null) queryBean.setQuery(q); return queryBean; }
/**** * 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); }
private SearchResult<AgencyAndId> searchForRoutes(SearchQueryBean query) throws ServiceException, InvalidArgumentServiceException { try { return _searchService.searchForRoutesByName(query.getQuery(), query.getMaxCount() + 1, query.getMinScoreToKeep()); } catch (IOException e) { throw new ServiceException(); } catch (ParseException e) { throw new InvalidArgumentServiceException("query", "queryParseError"); } }
private SearchResult<AgencyAndId> searchForRoutes(SearchQueryBean query) throws ServiceException, InvalidArgumentServiceException { try { return _searchService.searchForRoutesByShortName(query.getQuery(), query.getMaxCount() + 1, MIN_SEARCH_SCORE); } catch (IOException e) { throw new ServiceException(); } catch (ParseException e) { throw new InvalidArgumentServiceException("query", "queryParseError"); } }
public List<StopBean> getAllRevenueStops(AgencyWithCoverageBean agency) { SearchQueryBean query = new SearchQueryBean(); CoordinateBounds bounds = new CoordinateBounds(); double lat = agency.getLat(); double lon = agency.getLon(); double latSpan = agency.getLatSpan() / 2; double lonSpan = agency.getLonSpan() / 2; bounds.addPoint(lat - latSpan, lon - lonSpan); bounds.addPoint(lat + latSpan, lon + lonSpan); query.setBounds(bounds); query.setMaxCount(Integer.MAX_VALUE); return _scheduleHelperService.filterRevenueService(agency.getAgency(), getStops(query)); }
private List<StopsBean> fetchStopsFromGeocoder(String q) { List<StopsBean> result = new ArrayList<StopsBean>(); // FIXME HACK: append brooklyn to addresses to prevent manhattan adresses from being // returned instead--use google viewport biasing instead? if(q != null && q.isEmpty() == false) { q = q + " brooklyn, ny"; } List<GeocoderResult> geocoderResults = geocoderService.geocode(q).getResults(); for (GeocoderResult geocoderResult : geocoderResults) { double lat = geocoderResult.getLatitude(); double lng = geocoderResult.getLongitude(); CoordinateBounds bounds = SphericalGeometryLibrary.bounds(lat, lng, distanceToStops); // and add any stops for it SearchQueryBean searchQueryBean = makeSearchQuery(bounds); searchQueryBean.setMaxCount(100); StopsBean stops = transitService.getStops(searchQueryBean); result.add(stops); } return result; }
private StopsBean getStopsByBoundsAndQuery(SearchQueryBean queryBean) throws ServiceException { CoordinateBounds bounds = queryBean.getBounds(); String query = queryBean.getQuery(); int maxCount = queryBean.getMaxCount();
public StopsBean getStops(SearchQueryBean query) throws ServiceException { checkBounds(query.getBounds()); return _stopsBeanService.getStops(query); }
private StopsBean getStopsByBoundsAndQuery(SearchQueryBean queryBean) throws ServiceException { CoordinateBounds bounds = queryBean.getBounds(); String query = queryBean.getQuery(); int maxCount = queryBean.getMaxCount();
public RoutesBean getRoutes(SearchQueryBean query) throws ServiceException { checkBounds(query.getBounds()); return _routesBeanService.getRoutesForQuery(query); }
return INPUT; SearchQueryBean routesQuery = new SearchQueryBean(); routesQuery.setBounds(bounds); routesQuery.setMaxCount(10); routesQuery.setQuery(_routeName); routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
/**** * 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); }
return INPUT; SearchQueryBean searchQuery = new SearchQueryBean(); searchQuery.setBounds(bounds); searchQuery.setMaxCount(5); searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST); searchQuery.setQuery(_stopCode);
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); }
@Override public SearchResultCollection findRoutesStoppingWithinRegion( CoordinateBounds bounds, SearchResultFactory resultFactory) { SearchResultCollection results = new SearchResultCollection(); SearchQueryBean queryBean = new SearchQueryBean(); queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST); queryBean.setBounds(bounds); queryBean.setMaxCount(100); RoutesBean routes = null; try { routes = _transitDataService.getRoutes(queryBean); } catch (OutOfServiceAreaServiceException e) { return results; } Collections.sort(routes.getRoutes(), new RouteComparator()); for (RouteBean route : routes.getRoutes()) { results.addMatch(resultFactory.getRouteResultForRegion(route)); } return results; }
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); }
@Override public SearchResultCollection findRoutesStoppingNearPoint(Double latitude, Double longitude, SearchResultFactory resultFactory) { CoordinateBounds bounds = SphericalGeometryLibrary.bounds(latitude, longitude, DISTANCE_TO_ROUTES); SearchResultCollection results = new SearchResultCollection(); SearchQueryBean queryBean = new SearchQueryBean(); queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST); queryBean.setBounds(bounds); queryBean.setMaxCount(100); RoutesBean routes = null; try { routes = _transitDataService.getRoutes(queryBean); } catch (OutOfServiceAreaServiceException e) { return results; } Collections.sort(routes.getRoutes(), new RouteDistanceFromPointComparator(latitude, longitude)); for (RouteBean route : routes.getRoutes()) { SearchResult result = resultFactory.getRouteResult(route); results.addMatch(result); if (results.getMatches().size() > MAX_ROUTES) { break; } } return results; }
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); }
longitude, DISTANCE_TO_STOPS); SearchQueryBean queryBean = new SearchQueryBean(); queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST); queryBean.setBounds(bounds); queryBean.setMaxCount(100);
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); }