Search in sources :

Example 46 with CoordinatePoint

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;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 47 with CoordinatePoint

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

Example 48 with CoordinatePoint

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

Example 49 with CoordinatePoint

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);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Min(org.onebusaway.collections.Min) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) ParseException(org.apache.lucene.queryParser.ParseException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 50 with CoordinatePoint

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

Aggregations

CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)57 ArrayList (java.util.ArrayList)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)12 Test (org.junit.Test)10 XYPoint (org.onebusaway.geospatial.model.XYPoint)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)5 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)4 VehicleLocationRecordBean (org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)3 List (java.util.List)3 Min (org.onebusaway.collections.Min)3 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)3 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)3