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";
}
}
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);
}
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;
}
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);
}
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;
}
Aggregations