Search in sources :

Example 1 with StopEntry

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

the class TripStopTimesBeanServiceImpl method getStopTimesForTrip.

/**
 **
 * Private Methods
 ***
 */
private TripStopTimesBean getStopTimesForTrip(TripEntry trip) {
    AgencyAndId tripId = trip.getId();
    TripStopTimesBean bean = new TripStopTimesBean();
    TimeZone tz = _agencyService.getTimeZoneForAgencyId(tripId.getAgencyId());
    bean.setTimeZone(tz.getID());
    for (StopTimeEntry stopTime : trip.getStopTimes()) {
        TripStopTimeBean stBean = new TripStopTimeBean();
        stBean.setArrivalTime(stopTime.getArrivalTime());
        stBean.setDepartureTime(stopTime.getDepartureTime());
        StopEntry stopEntry = stopTime.getStop();
        StopBean stopBean = _stopBeanService.getStopForId(stopEntry.getId());
        stBean.setStop(stopBean);
        stBean.setDistanceAlongTrip(stopTime.getShapeDistTraveled());
        bean.addStopTime(stBean);
    }
    return bean;
}
Also used : TimeZone(java.util.TimeZone) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripStopTimeBean(org.onebusaway.transit_data.model.TripStopTimeBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopBean(org.onebusaway.transit_data.model.StopBean) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean)

Example 2 with StopEntry

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

the class GtfsRealtimeEntitySource method getStopId.

public Id getStopId(String stopId) {
    for (String agencyId : _agencyIds) {
        AgencyAndId id = new AgencyAndId(agencyId, stopId);
        StopEntry stop = _transitGraphDao.getStopEntryForId(id);
        if (stop != null)
            return ServiceAlertLibrary.id(id);
    }
    try {
        AgencyAndId id = AgencyAndId.convertFromString(stopId);
        StopEntry stop = _transitGraphDao.getStopEntryForId(id);
        if (stop != null)
            return ServiceAlertLibrary.id(id);
    } catch (IllegalArgumentException ex) {
    }
    _log.warn("stop not found with id \"{}\"", stopId);
    AgencyAndId id = new AgencyAndId(_agencyIds.get(0), stopId);
    return ServiceAlertLibrary.id(id);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)

Example 3 with StopEntry

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

the class RouteBeanServiceImpl method getStopsInOrder.

private List<StopEntry> getStopsInOrder(StopSequenceCollection block) {
    DirectedGraph<StopEntry> graph = new DirectedGraph<StopEntry>();
    for (StopSequence sequence : block.getStopSequences()) {
        StopEntry prev = null;
        for (StopEntry stop : sequence.getStops()) {
            if (prev != null) {
                // We do this to avoid cycles
                if (!graph.isConnected(stop, prev))
                    graph.addEdge(prev, stop);
            }
            prev = stop;
        }
    }
    StopGraphComparator c = new StopGraphComparator(graph);
    return graph.getTopologicalSort(c);
}
Also used : DirectedGraph(org.onebusaway.transit_data_federation.impl.DirectedGraph) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopGraphComparator(org.onebusaway.transit_data_federation.impl.StopGraphComparator) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence)

Example 4 with StopEntry

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

the class StopSequenceCollectionServiceImpl method getStopSequenceAsStopPairSet.

private Set<Pair<StopEntry>> getStopSequenceAsStopPairSet(StopSequence stopSequence) {
    Set<Pair<StopEntry>> pairs = new HashSet<Pair<StopEntry>>();
    StopEntry prev = null;
    for (StopEntry stop : stopSequence.getStops()) {
        if (prev != null) {
            Pair<StopEntry> pair = Tuples.pair(prev, stop);
            pairs.add(pair);
        }
        prev = stop;
    }
    return pairs;
}
Also used : StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Pair(org.onebusaway.collections.tuple.Pair) HashSet(java.util.HashSet)

Example 5 with StopEntry

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

the class StopSequenceCollectionServiceImpl method getSegmentForStopSequence.

/**
 * Compute a {@link Segment} object for the specified {@link StopSequence}. A
 * Segment generally captures the start and end location of the stop sequence,
 * along with the sequence's total length.
 *
 * @param pattern
 * @return
 */
private Segment getSegmentForStopSequence(StopSequence pattern) {
    Segment segment = new Segment();
    List<StopEntry> stops = pattern.getStops();
    StopEntry prev = null;
    for (StopEntry stop : stops) {
        if (prev == null) {
            segment.fromLat = stop.getStopLat();
            segment.fromLon = stop.getStopLon();
        } else {
            segment.distance += SphericalGeometryLibrary.distance(prev.getStopLat(), prev.getStopLon(), stop.getStopLat(), stop.getStopLon());
        }
        segment.toLat = stop.getStopLat();
        segment.toLon = stop.getStopLon();
        prev = stop;
    }
    return segment;
}
Also used : StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)

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