use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class TransitDataServiceTemplateImpl method getAgenciesWithCoverage.
// @Override
public List<AgencyWithCoverageBean> getAgenciesWithCoverage() throws ServiceException {
Map<String, CoordinateBounds> agencyIdsAndCoverageAreas = _agencyService.getAgencyIdsAndCoverageAreas();
List<AgencyWithCoverageBean> beans = new ArrayList<AgencyWithCoverageBean>();
for (Map.Entry<String, CoordinateBounds> entry : agencyIdsAndCoverageAreas.entrySet()) {
String agencyId = entry.getKey();
CoordinateBounds bounds = entry.getValue();
AgencyBean agencyBean = _agencyBeanService.getAgencyForId(agencyId);
if (agencyBean == null)
throw new ServiceException("agency not found: " + agencyId);
AgencyWithCoverageBean bean = new AgencyWithCoverageBean();
bean.setAgency(agencyBean);
bean.setLat((bounds.getMaxLat() + bounds.getMinLat()) / 2);
bean.setLon((bounds.getMaxLon() + bounds.getMinLon()) / 2);
bean.setLatSpan(bounds.getMaxLat() - bounds.getMinLat());
bean.setLonSpan(bounds.getMaxLon() - bounds.getMinLon());
beans.add(bean);
}
return beans;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class TransitDataServiceTemplateImpl method getAllRevenueStops.
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));
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class MonitoringActionBase method getBoxBounds.
protected CoordinateBounds getBoxBounds(String boundingCoordinates) throws NumberFormatException {
CoordinateBounds bounds = null;
if (boundingCoordinates != null) {
String[] coordinates = boundingCoordinates.split(",");
if (coordinates.length >= 4) {
CoordinateBounds userBounds = new CoordinateBounds(Double.parseDouble(coordinates[0]), Double.parseDouble(coordinates[1]), Double.parseDouble(coordinates[2]), Double.parseDouble(coordinates[3]));
bounds = userBounds;
}
}
return bounds;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class StopPointsV2Action method index.
public DefaultHttpHeaders index() throws IOException {
long responseTimestamp = getTime();
processGoogleAnalytics();
_realtimeService.setTime(responseTimestamp);
boolean useLineRefOnly = false;
Boolean upcomingServiceAllStops = null;
CoordinateBounds bounds = null;
boolean validBoundDistance = true;
// User Parameters
String boundingBox = _request.getParameter(BOUNDING_BOX);
String circle = _request.getParameter(CIRCLE);
String lineRef = _request.getParameter(LINE_REF);
String directionId = _request.getParameter(DIRECTION_REF);
String agencyId = _request.getParameter(OPERATOR_REF);
String hasUpcomingScheduledService = _request.getParameter(UPCOMING_SCHEDULED_SERVICE);
String detailLevelParam = _request.getParameter(STOP_POINTS_DETAIL_LEVEL);
// get the detail level parameter or set it to default if not specified
DetailLevel detailLevel;
if (DetailLevel.contains(detailLevelParam)) {
detailLevel = DetailLevel.valueOf(detailLevelParam.toUpperCase());
} else {
detailLevel = DetailLevel.NORMAL;
}
// Error Strings
String routeIdsErrorString = "";
String boundsErrorString = "";
/*
* We need to support the user providing no agency id which means 'all
agencies'. So, this array will hold a single agency if the user provides it or
all agencies if the user provides none. We'll iterate over them later while
querying for vehicles and routes
*/
List<String> agencyIds = processAgencyIds(agencyId);
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
routeIdsErrorString = processRouteIds(lineRef, routeIds, agencyIds);
// Calculate Bounds
try {
if (StringUtils.isNotBlank(circle)) {
bounds = getCircleBounds(circle);
if (bounds != null && !isValidBoundsDistance(bounds, MAX_BOUNDS_RADIUS)) {
boundsErrorString += "Provided values exceed allowed search radius of " + MAX_BOUNDS_RADIUS + "m ";
validBoundDistance = false;
}
} else if (StringUtils.isNotBlank(boundingBox)) {
bounds = getBoxBounds(boundingBox);
if (bounds != null && !isValidBoundBoxDistance(bounds, MAX_BOUNDS_DISTANCE)) {
boundsErrorString += "Provided values exceed allowed search distance of " + MAX_BOUNDS_DISTANCE + "m ";
validBoundDistance = false;
}
}
} catch (NumberFormatException nfe) {
boundsErrorString += ERROR_NON_NUMERIC;
}
// Check for case where only LineRef was provided
if (bounds == null) {
if (routeIds.size() > 0) {
useLineRefOnly = true;
} else {
boundsErrorString += ERROR_REQUIRED_PARAMS;
}
}
// Setup Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
filters.put(Filters.DIRECTION_REF, directionId);
filters.put(Filters.UPCOMING_SCHEDULED_SERVICE, hasUpcomingScheduledService);
// Annotated Stop Points
List<AnnotatedStopPointStructure> stopPoints = new ArrayList<AnnotatedStopPointStructure>();
Map<Boolean, List<AnnotatedStopPointStructure>> stopPointsMap;
// Error Handler
Exception error = null;
if ((bounds == null && !useLineRefOnly) || (_request.getParameter(LINE_REF) != null && routeIds.size() == 0) || !validBoundDistance) {
String errorString = (boundsErrorString + " " + routeIdsErrorString).trim();
error = new Exception(errorString);
} else {
if (useLineRefOnly) {
stopPointsMap = _realtimeService.getAnnotatedStopPointStructures(agencyIds, routeIds, detailLevel, responseTimestamp, filters);
} else {
stopPointsMap = _realtimeService.getAnnotatedStopPointStructures(bounds, agencyIds, routeIds, detailLevel, responseTimestamp, filters);
}
for (Map.Entry<Boolean, List<AnnotatedStopPointStructure>> entry : stopPointsMap.entrySet()) {
if (entry.getValue().size() > 0)
upcomingServiceAllStops = entry.getKey();
stopPoints.addAll(entry.getValue());
}
}
_response = generateSiriResponse(stopPoints, upcomingServiceAllStops, error, responseTimestamp);
try {
this._servletResponse.getWriter().write(getStopPoints());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.
the class RealtimeServiceTest method testStopPointsByBounds.
@Test
public void testStopPointsByBounds() throws Exception {
// MOCKS
// Coordinate Bounds
CoordinateBounds bounds = new CoordinateBounds(Double.parseDouble("47.612813"), Double.parseDouble("-122.339662"), Double.parseDouble("47.608813"), Double.parseDouble("-122.337662"));
// Stops For Bounds
StopsBean stopsBean = new StopsBean();
stopsBean.setStops(stops);
when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean);
when(transitDataService.getStops(any(SearchQueryBean.class))).thenReturn(stopsBean);
when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean);
when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
// EXPECTED
LineDirectionStructure lds = new LineDirectionStructure();
DirectionRefStructure drs = new DirectionRefStructure();
LineRefStructure lrs = new LineRefStructure();
lds.setDirectionRef(drs);
lds.setLineRef(lrs);
drs.setValue("0");
lrs.setValue("1_100194");
LocationStructure ls = new LocationStructure();
BigDecimal lat = new BigDecimal(47.610813);
BigDecimal lon = new BigDecimal(-122.338662);
ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue("3rd Ave & Pine St");
List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
stopNames.add(stopName);
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue("1_430");
Boolean monitored = true;
AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
mockStopPoint.setLocation(ls);
mockStopPoint.getStopName().add(stopName);
mockStopPoint.setStopPointRef(stopPointRef);
mockStopPoint.setMonitored(monitored);
// REALTIME ARGUMENTS
// Agency Ids
List<String> agencyIds = new ArrayList<String>();
String agencyId = "1";
agencyIds.add(agencyId);
// Route Ids
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
AgencyAndId routeId = AgencyAndIdLibrary.convertFromString("1_100194");
routeIds.add(routeId);
// Detail Level
DetailLevel detailLevel = DetailLevel.NORMAL;
// Time
long time = System.currentTimeMillis();
// Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
Map<Boolean, List<AnnotatedStopPointStructure>> actualResult = realtimeService.getAnnotatedStopPointStructures(bounds, agencyIds, routeIds, detailLevel, time, filters);
AnnotatedStopPointStructure actualStopPoint = actualResult.get(true).get(0);
assertTrue(isEqual(mockStopPoint, actualStopPoint));
}
Aggregations