Search in sources :

Example 31 with StopEntry

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

the class GtfsController method getStops.

@RequestMapping(value = "/stops/{agencyId}/{id}")
@ResponseBody
public List<CoordinatePoint> getStops(@PathVariable String agencyId, @PathVariable String id) {
    AgencyAndId routeId = new AgencyAndId(agencyId, id);
    RouteEntry route = _transitGraphDao.getRouteForId(routeId);
    TripEntry trip = routeToTrip(route);
    List<StopTimeEntry> stopTimes = trip.getStopTimes();
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    for (StopTimeEntry entry : stopTimes) {
        StopEntry stop = entry.getStop();
        points.add(stop.getStopLocation());
    }
    return points;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 32 with StopEntry

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

the class StopTimeEntriesFactory method ensureStopTimesHaveShapeDistanceTraveledSet.

/**
 * We have to make sure shape distance traveled is set, even if we don't have
 * shape information
 *
 * @param stopTimes
 * @param shapePoints potentially null
 */
private void ensureStopTimesHaveShapeDistanceTraveledSet(List<StopTimeEntryImpl> stopTimes, ShapePoints shapePoints) {
    boolean distanceTraveledSet = false;
    // Do we have shape information?
    if (shapePoints != null) {
        try {
            PointAndIndex[] stopTimePoints = _distanceAlongShapeLibrary.getDistancesAlongShape(shapePoints, stopTimes);
            for (int i = 0; i < stopTimePoints.length; i++) {
                PointAndIndex pindex = stopTimePoints[i];
                StopTimeEntryImpl stopTime = stopTimes.get(i);
                stopTime.setShapePointIndex(pindex.index);
                stopTime.setShapeDistTraveled(pindex.distanceAlongShape);
            }
            distanceTraveledSet = true;
        } catch (StopIsTooFarFromShapeException ex) {
            StopTimeEntry stopTime = ex.getStopTime();
            TripEntry trip = stopTime.getTrip();
            StopEntry stop = stopTime.getStop();
            AgencyAndId shapeId = trip.getShapeId();
            CoordinatePoint point = ex.getPoint();
            PointAndIndex pindex = ex.getPointAndIndex();
            _log.warn("Stop is too far from shape: trip=" + trip.getId() + " stop=" + stop.getId() + " stopLat=" + stop.getStopLat() + " stopLon=" + stop.getStopLon() + " shapeId=" + shapeId + " shapePoint=" + point + " index=" + pindex.index + " distance=" + pindex.distanceFromTarget);
        } catch (DistanceAlongShapeException ex) {
            _invalidStopToShapeMappingExceptionCount++;
        } catch (IllegalArgumentException iae) {
            _log.warn("Stop has illegal coordinates along shapes=" + shapePoints);
        }
    }
    if (!distanceTraveledSet) {
        // Make do without
        double d = 0;
        StopTimeEntryImpl prev = null;
        for (StopTimeEntryImpl stopTime : stopTimes) {
            if (prev != null) {
                CoordinatePoint from = prev.getStop().getStopLocation();
                CoordinatePoint to = stopTime.getStop().getStopLocation();
                d += SphericalGeometryLibrary.distance(from, to);
            }
            stopTime.setShapeDistTraveled(d);
            prev = stopTime;
        }
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) DistanceAlongShapeException(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.DistanceAlongShapeException) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) StopIsTooFarFromShapeException(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary.StopIsTooFarFromShapeException) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)

Example 33 with StopEntry

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

the class StopSequenceCollectionServiceImpl method computeContinuations.

/**
 * For each given StopSequence, we wish to compute the set of StopSequences
 * that continue the given StopSequence. We say one StopSequence continues
 * another if the two stops sequences have the same route and direction id and
 * each trip in the first StopSequence is immediately followed by a Trip from
 * the second StopSequence, as defined by a block id.
 *
 * @param sequenceStats
 * @param sequencesByGroupId
 */
private void computeContinuations(Map<StopSequence, PatternStats> sequenceStats, Map<String, List<StopSequence>> sequencesByGroupId) {
    Map<BlockTripEntry, StopSequence> stopSequencesByTrip = new HashMap<BlockTripEntry, StopSequence>();
    Map<StopSequence, String> stopSequenceGroupIds = new HashMap<StopSequence, String>();
    for (Map.Entry<String, List<StopSequence>> entry : sequencesByGroupId.entrySet()) {
        String id = entry.getKey();
        for (StopSequence sequence : entry.getValue()) stopSequenceGroupIds.put(sequence, id);
    }
    for (StopSequence sequence : sequenceStats.keySet()) {
        String groupId = stopSequenceGroupIds.get(sequence);
        for (BlockTripEntry trip : sequence.getTrips()) {
            BlockTripEntry prevTrip = trip.getPreviousTrip();
            if (prevTrip == null)
                continue;
            StopSequence prevSequence = stopSequencesByTrip.get(prevTrip);
            // No continuations if incoming is not part of the sequence collection
            if (prevSequence == null)
                continue;
            // No continuation if it's the same stop sequence
            if (prevSequence.equals(sequence))
                continue;
            // No contination if the the block group ids don't match
            String prevGroupId = stopSequenceGroupIds.get(prevSequence);
            if (!groupId.equals(prevGroupId))
                continue;
            StopEntry prevStop = prevSequence.getStops().get(prevSequence.getStops().size() - 1);
            StopEntry nextStop = sequence.getStops().get(0);
            double d = SphericalGeometryLibrary.distance(prevStop.getStopLat(), prevStop.getStopLon(), nextStop.getStopLat(), nextStop.getStopLon());
            if (d < 5280 / 4) {
                /*
           * System.out.println("distance=" + d + " from=" + prevStop.getId() +
           * " to=" + nextStop.getId() + " ssFrom=" + prevSequence.getId() +
           * " ssTo=" + stopSequence.getId());
           */
                PatternStats stats = sequenceStats.get(prevSequence);
                stats.continuations.add(sequence);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) List(java.util.List) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence)

Example 34 with StopEntry

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

the class StopSequencesServiceImpl method getStopSequencesForTrips.

@Override
public List<StopSequence> getStopSequencesForTrips(List<BlockTripEntry> trips) {
    Map<StopSequenceKey, List<BlockTripEntry>> tripsByStopSequenceKey = new FactoryMap<StopSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
    for (BlockTripEntry blockTrip : trips) {
        TripEntry trip = blockTrip.getTrip();
        String directionId = trip.getDirectionId();
        if (directionId == null)
            directionId = NO_DIRECTION_ID;
        AgencyAndId shapeId = trip.getShapeId();
        if (shapeId == null || !shapeId.hasValues())
            shapeId = NO_SHAPE_ID;
        List<StopEntry> stops = getStopTimesAsStops(trip.getStopTimes());
        StopSequenceKey key = new StopSequenceKey(stops, directionId, shapeId);
        tripsByStopSequenceKey.get(key).add(blockTrip);
    }
    List<StopSequence> sequences = new ArrayList<StopSequence>();
    for (Map.Entry<StopSequenceKey, List<BlockTripEntry>> entry : tripsByStopSequenceKey.entrySet()) {
        StopSequenceKey key = entry.getKey();
        StopSequence ss = new StopSequence();
        ss.setId(sequences.size());
        ss.setRoute(null);
        ss.setStops(key.getStops());
        if (!key.getDirectionId().equals(NO_DIRECTION_ID))
            ss.setDirectionId(key.getDirectionId());
        if (!key.getShapeId().equals(NO_SHAPE_ID))
            ss.setShapeId(key.getShapeId());
        ss.setTrips(entry.getValue());
        ss.setTripCount(entry.getValue().size());
        sequences.add(ss);
    }
    return sequences;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence) List(java.util.List) ArrayList(java.util.ArrayList) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 35 with StopEntry

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

the class WhereGeospatialServiceImpl method initialize.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.STOP_GEOSPATIAL_INDEX)
public void initialize() {
    List<StopEntry> stops = _transitGraphDao.getAllStops();
    if (stops.size() == 0) {
        _tree = null;
        return;
    }
    _tree = new STRtree(stops.size());
    for (StopEntry stop : stops) {
        float x = (float) stop.getStopLon();
        float y = (float) stop.getStopLat();
        Envelope env = new Envelope(x, x, y, y);
        _tree.insert(env, stop.getId());
    }
    _tree.build();
}
Also used : STRtree(com.vividsolutions.jts.index.strtree.STRtree) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Envelope(com.vividsolutions.jts.geom.Envelope) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

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