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);
}
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();
}
Aggregations