Search in sources :

Example 51 with StopEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.

the class BlockIndexServiceImpl method loadStopTripIndices.

private void loadStopTripIndices() {
    // Clear any existing indices
    for (StopEntry stop : _graphDao.getAllStops()) {
        StopEntryImpl stopImpl = (StopEntryImpl) stop;
        stopImpl.getStopTripIndices().clear();
        stopImpl.getFrequencyStopTripIndices().clear();
    }
    for (BlockSequenceIndex index : _blockSequenceIndices) {
        BlockSequence sequence = index.getSequences().get(0);
        int offset = 0;
        for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
            StopTimeEntry stopTime = bst.getStopTime();
            StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
            BlockStopSequenceIndex blockStopTripIndex = new BlockStopSequenceIndex(index, offset);
            stop.addBlockStopTripIndex(blockStopTripIndex);
            offset++;
        }
    }
    for (FrequencyBlockTripIndex index : _frequencyBlockTripIndices) {
        BlockTripEntry trip = index.getTrips().get(0);
        int offset = 0;
        for (BlockStopTimeEntry bst : trip.getStopTimes()) {
            StopTimeEntry stopTime = bst.getStopTime();
            StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
            FrequencyStopTripIndex stopTripIndex = new FrequencyStopTripIndex(index, offset);
            stop.addFrequencyStopTripIndex(stopTripIndex);
            offset++;
        }
    }
}
Also used : BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) FrequencyStopTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyStopTripIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 52 with StopEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.

the class BlockIndexServiceImpl method loadStopTimeIndices.

private void loadStopTimeIndices() {
    // Clear any existing indices
    for (StopEntry stop : _graphDao.getAllStops()) {
        StopEntryImpl stopImpl = (StopEntryImpl) stop;
        stopImpl.getStopTimeIndices().clear();
        stopImpl.getFrequencyStopTimeIndices().clear();
    }
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    factory.setVerbose(true);
    List<BlockStopTimeIndex> indices = factory.createIndices(_graphDao.getAllBlocks());
    for (BlockStopTimeIndex index : indices) {
        StopEntryImpl stop = (StopEntryImpl) index.getStop();
        stop.addStopTimeIndex(index);
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = factory.createFrequencyIndices(_graphDao.getAllBlocks());
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
        StopEntryImpl stop = (StopEntryImpl) index.getStop();
        stop.addFrequencyStopTimeIndex(index);
    }
}
Also used : FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 53 with StopEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry 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)

Example 54 with StopEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactory method getBlockStopTimeAsKey.

private BlockStopTimeKey getBlockStopTimeAsKey(BlockStopTimeEntry blockStopTime) {
    BlockTripEntry blockTrip = blockStopTime.getTrip();
    BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    StopEntry stop = stopTime.getStop();
    return new BlockStopTimeKey(blockConfig.getServiceIds(), stop.getId());
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Aggregations

StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)54 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)28 ArrayList (java.util.ArrayList)15 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)14 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)12 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)12 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)10 List (java.util.List)9 FactoryMap (org.onebusaway.collections.FactoryMap)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Test (org.junit.Test)8 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopBean (org.onebusaway.transit_data.model.StopBean)4