Search in sources :

Example 56 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.

the class BlockStatusServiceImpl method getBlocksForBounds.

@Override
public List<BlockLocation> getBlocksForBounds(CoordinateBounds bounds, long time) {
    long timeFrom = time - _runningLateWindow * 1000;
    long timeTo = time + _runningEarlyWindow * 1000;
    List<BlockInstance> instances = _blockGeospatialService.getActiveScheduledBlocksPassingThroughBounds(bounds, timeFrom, timeTo);
    List<BlockLocation> locations = getAsLocations(instances, time);
    List<BlockLocation> inRange = new ArrayList<BlockLocation>();
    for (BlockLocation location : locations) {
        CoordinatePoint p = location.getLocation();
        if (p != null && bounds.contains(p))
            inRange.add(location);
    }
    return inRange;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation)

Example 57 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationBetweenStopTimes.

private ScheduledBlockLocation getScheduledBlockLocationBetweenStopTimes(List<BlockStopTimeEntry> stopTimes, int scheduleTime, int stopTimeIndex) {
    BlockStopTimeEntry blockBefore = stopTimes.get(stopTimeIndex - 1);
    BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);
    StopTimeEntry before = blockBefore.getStopTime();
    StopTimeEntry after = blockAfter.getStopTime();
    ScheduledBlockLocation result = new ScheduledBlockLocation();
    result.setScheduledTime(scheduleTime);
    result.setInService(true);
    result.setStopTimeIndex(stopTimeIndex);
    int fromTime = before.getDepartureTime();
    int toTime = after.getArrivalTime();
    int fromTimeOffset = fromTime - scheduleTime;
    int toTimeOffset = toTime - scheduleTime;
    if (Math.abs(fromTimeOffset) < Math.abs(toTimeOffset)) {
        result.setClosestStop(blockBefore);
        result.setClosestStopTimeOffset(fromTimeOffset);
    } else {
        result.setClosestStop(blockAfter);
        result.setClosestStopTimeOffset(toTimeOffset);
    }
    result.setPreviousStop(blockBefore);
    result.setNextStop(blockAfter);
    result.setNextStopTimeOffset(toTimeOffset);
    double ratio = (scheduleTime - fromTime) / ((double) (toTime - fromTime));
    double fromDistance = blockBefore.getDistanceAlongBlock();
    double toDistance = blockAfter.getDistanceAlongBlock();
    double distanceAlongBlock = ratio * (toDistance - fromDistance) + fromDistance;
    result.setDistanceAlongBlock(distanceAlongBlock);
    int shapePointIndexFrom = -1;
    int shapePointIndexTo = -1;
    /**
     * Are we between trips? Where is the transition point?
     */
    if (!before.getTrip().equals(after.getTrip())) {
        if (distanceAlongBlock >= blockAfter.getTrip().getDistanceAlongBlock()) {
            result.setActiveTrip(blockAfter.getTrip());
            shapePointIndexFrom = 0;
            shapePointIndexTo = nextShapePointIndex(after);
        } else {
            result.setActiveTrip(blockBefore.getTrip());
            shapePointIndexFrom = before.getShapePointIndex();
            shapePointIndexTo = Integer.MAX_VALUE;
        }
    } else {
        result.setActiveTrip(blockBefore.getTrip());
        shapePointIndexFrom = before.getShapePointIndex();
        shapePointIndexTo = nextShapePointIndex(after);
    }
    BlockTripEntry activeTrip = result.getActiveTrip();
    PointAndOrientation po = getLocationAlongShape(activeTrip, distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);
    if (po != null) {
        result.setLocation(po.getPoint());
        result.setOrientation(po.getOrientation());
        return result;
    }
    StopEntry beforeStop = before.getStop();
    StopEntry afterStop = after.getStop();
    double latFrom = beforeStop.getStopLat();
    double lonFrom = beforeStop.getStopLon();
    double latTo = afterStop.getStopLat();
    double lonTo = afterStop.getStopLon();
    double lat = (latTo - latFrom) * ratio + latFrom;
    double lon = (lonTo - lonFrom) * ratio + lonFrom;
    CoordinatePoint location = new CoordinatePoint(lat, lon);
    result.setLocation(location);
    double orientation = SphericalGeometryLibrary.getOrientation(latFrom, lonFrom, latTo, lonTo);
    result.setOrientation(orientation);
    return result;
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

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