use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class AgencyServiceImpl method getAgencyIdsAndCenterPoints.
@Cacheable
public Map<String, CoordinatePoint> getAgencyIdsAndCenterPoints() {
Map<String, CoordinatePoint> centersByAgencyId = new HashMap<String, CoordinatePoint>();
for (AgencyEntry agency : _graph.getAllAgencies()) {
StopsCenterOfMass centerOfMass = new StopsCenterOfMass();
for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
for (RouteEntry route : routeCollection.getChildren()) {
for (TripEntry trip : route.getTrips()) {
for (StopTimeEntry stopTime : trip.getStopTimes()) {
StopEntry stop = stopTime.getStop();
centerOfMass.lats += stop.getStopLat();
centerOfMass.lons += stop.getStopLon();
centerOfMass.count++;
}
}
}
}
if (centerOfMass.count == 0) {
_log.warn("Agency has no service: " + agency);
} else {
double lat = centerOfMass.lats / centerOfMass.count;
double lon = centerOfMass.lons / centerOfMass.count;
centersByAgencyId.put(agency.getId(), new CoordinatePoint(lat, lon));
}
}
return centersByAgencyId;
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class MetricResource method findInvalidLatLon.
private Collection<CoordinatePoint> findInvalidLatLon(String agencyId, Set<CoordinatePoint> coordinatePoints) {
List<CoordinatePoint> invalid = new ArrayList<CoordinatePoint>();
List<CoordinateBounds> bounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
// ensure we have a valid bounding box for requested agency
if (bounds == null || bounds.isEmpty()) {
_log.warn("no bounds configured for agency " + agencyId);
for (CoordinatePoint pt : coordinatePoints) {
invalid.add(pt);
}
return invalid;
}
for (CoordinateBounds bound : bounds) {
boolean found = false;
for (CoordinatePoint pt : coordinatePoints) {
// check if point is inside bounds
if (bound.contains(pt)) {
found = true;
}
if (!found) {
invalid.add(pt);
}
}
}
_log.debug("agency " + agencyId + " had " + invalid.size() + " invalid out of " + coordinatePoints.size());
return invalid;
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class LocationResource method findInvalidLatLon.
private Collection<CoordinatePoint> findInvalidLatLon(String agencyId, Set<CoordinatePoint> coordinatePoints) {
List<CoordinatePoint> invalid = new ArrayList<CoordinatePoint>();
List<CoordinateBounds> bounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
// ensure we have a valid bounding box for requested agency
if (bounds == null || bounds.isEmpty()) {
_log.warn("no bounds configured for agency " + agencyId);
for (CoordinatePoint pt : coordinatePoints) {
invalid.add(pt);
}
return invalid;
}
for (CoordinateBounds bound : bounds) {
boolean found = false;
for (CoordinatePoint pt : coordinatePoints) {
// check if point is inside bounds
if (bound.contains(pt)) {
found = true;
}
if (!found) {
invalid.add(pt);
}
}
}
_log.debug("agency " + agencyId + " had " + invalid.size() + " invalid out of " + coordinatePoints.size());
return invalid;
}
use of org.onebusaway.geospatial.model.CoordinatePoint 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.CoordinatePoint in project onebusaway-application-modules by camsys.
the class VehicleStatusBeanServiceImpl method getBlockLocationRecordAsVehicleLocationRecord.
private VehicleLocationRecordBean getBlockLocationRecordAsVehicleLocationRecord(BlockLocationRecord record) {
VehicleLocationRecordBean bean = new VehicleLocationRecordBean();
bean.setBlockId(AgencyAndIdLibrary.convertToString(record.getBlockId()));
if (record.getPhase() != null)
bean.setPhase(record.getPhase().toLabel());
CoordinatePoint location = record.getLocation();
if (location != null)
bean.setCurrentLocation(location);
if (record.getOrientation() != null)
bean.setCurrentOrientation(record.getOrientation());
if (record.getDistanceAlongBlock() != null)
bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
if (record.getScheduleDeviation() != null)
bean.setScheduleDeviation(record.getScheduleDeviation());
bean.setStatus(record.getStatus());
bean.setServiceDate(record.getServiceDate());
bean.setTimeOfRecord(record.getTime());
bean.setTripId(AgencyAndIdLibrary.convertToString(record.getTripId()));
bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
return bean;
}
Aggregations