Search in sources :

Example 6 with PointAndOrientation

use of org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImpl method interpolateLocation.

private ScheduledBlockLocation interpolateLocation(BlockStopTimeEntry blockPrevious, BlockStopTimeEntry blockFrom, BlockStopTimeEntry blockTo, double distanceAlongBlock, int stopTimeIndex) {
    if (distanceAlongBlock < 0.0)
        return null;
    StopTimeEntry from = blockFrom.getStopTime();
    StopTimeEntry to = blockTo.getStopTime();
    double r = (distanceAlongBlock - blockFrom.getDistanceAlongBlock()) / (blockTo.getDistanceAlongBlock() - blockFrom.getDistanceAlongBlock());
    int scheduledTime = (int) (r * (to.getArrivalTime() - from.getDepartureTime()) + from.getDepartureTime());
    if (r > 1)
        scheduledTime += to.getSlackTime();
    BlockTripEntry activeTrip = distanceAlongBlock < blockTo.getDistanceAlongBlock() ? blockFrom.getTrip() : blockTo.getTrip();
    BlockStopTimeEntry closestStop = r < 0.5 ? blockFrom : blockTo;
    BlockStopTimeEntry previousStop = null;
    BlockStopTimeEntry nextStop = null;
    int shapePointIndexFrom = -1;
    int shapePointIndexTo = -1;
    if (r <= 0) {
        /**
         * Location along the block is before the two stop times
         */
        previousStop = blockPrevious;
        nextStop = blockFrom;
        shapePointIndexFrom = 0;
        shapePointIndexTo = nextShapePointIndex(from);
    } else if (r <= 1.0) {
        /**
         * Location along the block is between the two stop times
         */
        previousStop = blockFrom;
        nextStop = blockTo;
        shapePointIndexFrom = from.getShapePointIndex();
        shapePointIndexTo = nextShapePointIndex(to);
    } else {
        /**
         * Location along the block is after the two stop times
         */
        shapePointIndexFrom = to.getShapePointIndex();
        shapePointIndexTo = Integer.MAX_VALUE;
    }
    ScheduledBlockLocation location = new ScheduledBlockLocation();
    location.setActiveTrip(activeTrip);
    location.setClosestStop(closestStop);
    location.setClosestStopTimeOffset(closestStop.getStopTime().getArrivalTime() - scheduledTime);
    location.setPreviousStop(previousStop);
    location.setNextStop(nextStop);
    if (nextStop != null)
        location.setNextStopTimeOffset(nextStop.getStopTime().getArrivalTime() - scheduledTime);
    location.setInService(nextStop != null);
    location.setStopTimeIndex(stopTimeIndex);
    location.setDistanceAlongBlock(distanceAlongBlock);
    location.setScheduledTime(scheduledTime);
    /**
     * In this case, distance along block and distance along trip are the same
     * because we are still in the first trip of the block
     */
    PointAndOrientation po = getLocationAlongShape(activeTrip, distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);
    if (po != null) {
        location.setLocation(po.getPoint());
        location.setOrientation(po.getOrientation());
    }
    return location;
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) 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) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

PointAndOrientation (org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation)6 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)4 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)3 DoubleArrayList (cern.colt.list.DoubleArrayList)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 DistanceTraveledShapePointIndex (org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex)1 ShapePointIndex (org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex)1 ProjectedPoint (org.onebusaway.transit_data_federation.model.ProjectedPoint)1 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)1 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1