Search in sources :

Example 1 with ShapePointIndex

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

the class ScheduledBlockLocationServiceImpl method getLocationAlongShape.

private PointAndOrientation getLocationAlongShape(BlockTripEntry activeBlockTrip, double distanceAlongBlock, int shapePointIndexFrom, int shapePointIndexTo) {
    TripEntry activeTrip = activeBlockTrip.getTrip();
    AgencyAndId shapeId = activeTrip.getShapeId();
    if (shapeId == null)
        return null;
    ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId);
    if (shapePoints == null || shapePoints.isEmpty())
        return null;
    /**
     * We allow callers of this method to specify an arbitrarily high
     * shapePointIndexTo, knowing we'll bound it by the max number of points
     */
    shapePointIndexFrom = Math.min(shapePointIndexFrom, shapePoints.getSize());
    shapePointIndexTo = Math.min(shapePointIndexTo, shapePoints.getSize());
    double distanceAlongTrip = distanceAlongBlock - activeBlockTrip.getDistanceAlongBlock();
    ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(distanceAlongTrip, shapePointIndexFrom, shapePointIndexTo);
    return shapePointIndexMethod.getPointAndOrientation(shapePoints);
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex)

Example 2 with ShapePointIndex

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

the class GenerateNarrativesTask method getAllOrientationsForStop.

private Collection<PointAndOrientation> getAllOrientationsForStop(NarrativeProviderImpl provider, StopEntry stop) {
    List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop);
    List<PointAndOrientation> pos = new ArrayList<PointAndOrientation>();
    Map<ShapeIdAndDistance, PointAndOrientation> orientationsByKey = new HashMap<ShapeIdAndDistance, PointAndOrientation>();
    for (BlockStopTimeIndex stopTimeIndex : stopTimeIndices) {
        for (BlockStopTimeEntry blockStopTime : stopTimeIndex.getStopTimes()) {
            StopTimeEntry stopTime = blockStopTime.getStopTime();
            TripEntry trip = stopTime.getTrip();
            AgencyAndId shapeId = trip.getShapeId();
            if (shapeId == null)
                continue;
            ShapePoints shapePoints = provider.getShapePointsForId(shapeId);
            if (shapePoints == null)
                continue;
            int shapePointIndex = stopTime.getShapePointIndex();
            if (shapePointIndex == -1)
                continue;
            ShapeIdAndDistance key = new ShapeIdAndDistance(shapeId, stopTime.getShapeDistTraveled());
            PointAndOrientation orientation = orientationsByKey.get(key);
            if (orientation == null) {
                int indexFrom = Math.max(0, shapePointIndex - 5);
                int indexTo = Math.min(shapePoints.getSize(), shapePointIndex + 5);
                ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(stopTime.getShapeDistTraveled(), indexFrom, indexTo);
                orientation = shapePointIndexMethod.getPointAndOrientation(shapePoints);
                if (orientation == null)
                    continue;
                orientationsByKey.put(key, orientation);
            }
            pos.add(orientation);
        }
    }
    return orientationsByKey.values();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) ShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

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