Search in sources :

Example 21 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class PlaceFinderTraverseVisitor method handlePatternsAtStop.

private void handlePatternsAtStop(Stop stop, double distance) {
    if (includePatternAtStops) {
        List<TripPattern> patterns = routingService.getPatternsForStop(stop).stream().filter(pattern -> filterByModes == null || filterByModes.contains(pattern.getMode())).filter(pattern -> filterByRoutes == null || filterByRoutes.contains(pattern.route.getId())).filter(pattern -> pattern.canBoard(pattern.getStopIndex(stop))).collect(toList());
        for (TripPattern pattern : patterns) {
            String seenKey = pattern.route.getId().toString() + ":" + pattern.getId().toString();
            if (!seenPatternAtStops.contains(seenKey)) {
                PatternAtStop row = new PatternAtStop(stop, pattern);
                PlaceAtDistance place = new PlaceAtDistance(row, distance);
                placesFound.add(place);
                seenPatternAtStops.add(seenKey);
            }
        }
    }
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) SearchTerminationStrategy(org.opentripplanner.routing.algorithm.astar.strategies.SearchTerminationStrategy) RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) Vertex(org.opentripplanner.routing.graph.Vertex) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) Set(java.util.Set) TraverseVisitor(org.opentripplanner.routing.algorithm.astar.TraverseVisitor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) State(org.opentripplanner.routing.core.State) TransitMode(org.opentripplanner.model.TransitMode) Edge(org.opentripplanner.routing.graph.Edge) TripPattern(org.opentripplanner.model.TripPattern)

Example 22 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class RideMapper method rideForTransitPathLeg.

public static Ride rideForTransitPathLeg(TransitPathLeg leg, TransitLayer transitLayer) {
    TransitPathLeg<TripSchedule> transitPathLeg = leg.asTransitLeg();
    TripSchedule tripSchedule = transitPathLeg.trip();
    Ride ride = new Ride();
    TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
    ride.firstStop = transitLayer.getStopByIndex(transitPathLeg.fromStop());
    ride.lastStop = transitLayer.getStopByIndex(transitPathLeg.toStop());
    ride.startZone = ride.firstStop.getFirstZoneAsString();
    ride.endZone = ride.lastStop.getFirstZoneAsString();
    // In almost all cases (except some loop routes) this should get the right set of zones passed through.
    // We don't have the position of the stops within the pattern so can't readily get more accurate than this.
    boolean onBoard = false;
    for (Stop stop : tripPattern.getStops()) {
        if (stop == ride.firstStop) {
            onBoard = true;
        }
        if (onBoard) {
            ride.zones.add(stop.getFirstZoneAsString());
            if (stop == ride.lastStop)
                break;
        }
    }
    ride.agency = tripPattern.route.getAgency().getId();
    ride.route = tripPattern.route.getId();
    ride.trip = tripSchedule.getOriginalTripTimes().trip.getId();
    // TODO verify that times are in seconds after midnight
    ride.startTime = transitPathLeg.fromTime();
    ride.endTime = transitPathLeg.toTime();
    // In the default fare service, we classify rides by mode.
    ride.classifier = tripPattern.getMode();
    return ride;
}
Also used : Stop(org.opentripplanner.model.Stop) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) TripPattern(org.opentripplanner.model.TripPattern)

Example 23 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class StreetSearch method route.

/**
 * return access times (in seconds) by stop index
 */
void route(Place place, boolean fromOrigin) {
    Vertex vertex = null;
    if (place.stopId != null) {
        vertex = graph.getVertex(place.stopId.getId());
    }
    if (vertex == null) {
        vertex = new TemporaryStreetLocation(place.name, new Coordinate(place.coordinate.longitude(), place.coordinate.latitude()), new NonLocalizedString(place.name), !fromOrigin);
        splitter.link(vertex);
    }
    List<StopAtDistance> stopAtDistanceList = nearbyStopFinder.findNearbyStopsViaStreets(Set.of(vertex), !fromOrigin, true);
    if (stopAtDistanceList.isEmpty()) {
        throw new RuntimeException("No stops found nearby: " + place);
    }
    for (StopAtDistance stopAtDistance : stopAtDistanceList) {
        if (!(stopAtDistance.stop instanceof Stop))
            continue;
        int stopIndex = transitLayer.getIndexByStop((Stop) stopAtDistance.stop);
        int accessTimeSec = (int) stopAtDistance.edges.stream().map(Edge::getDistanceMeters).collect(Collectors.summarizingDouble(Double::doubleValue)).getSum();
        resultTimesSecByStopIndex.put(stopIndex, accessTimeSec);
        pathsByStopIndex.put(stopIndex, stopAtDistance);
    }
    LOG.debug("Found {} {} stops", resultTimesSecByStopIndex.size(), fromOrigin ? "access" : "egress");
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) Coordinate(org.locationtech.jts.geom.Coordinate) Stop(org.opentripplanner.model.Stop) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance)

Example 24 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class AlertToLegMapper method getAlertsForStopAndTrip.

private static Collection<TransitAlert> getAlertsForStopAndTrip(Graph graph, FeedScopedId stopId, FeedScopedId tripId, boolean checkParentStop) {
    Stop stop = graph.index.getStopForId(stopId);
    if (stop == null) {
        return new ArrayList<>();
    }
    Collection<TransitAlert> alertsForStopAndTrip = graph.getTransitAlertService().getStopAndTripAlerts(stopId, tripId);
    if (checkParentStop) {
        if (alertsForStopAndTrip == null) {
            alertsForStopAndTrip = new HashSet<>();
        }
        if (stop.isPartOfStation()) {
            // Also check parent
            Collection<TransitAlert> alerts = graph.getTransitAlertService().getStopAndTripAlerts(stop.getParentStation().getId(), tripId);
            if (alerts != null) {
                alertsForStopAndTrip.addAll(alerts);
            }
        }
    // TODO SIRI: Add support for fetching alerts attached to MultiModal-stops
    // if (stop.getMultiModalStation() != null) {
    // //Also check multimodal parent
    // FeedScopedId multimodalStopId = new FeedScopedId(stopId.getAgencyId(), stop.getMultiModalStation());
    // Collection<AlertPatch> multimodalStopAlerts = graph.index.getAlertsForStopAndTrip(multimodalStopId, tripId);
    // if (multimodalStopAlerts != null) {
    // alertsForStopAndTrip.addAll(multimodalStopAlerts);
    // }
    // }
    }
    return alertsForStopAndTrip;
}
Also used : TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList)

Example 25 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class AlertToLegMapper method getAlertsForStop.

private static Collection<TransitAlert> getAlertsForStop(Graph graph, FeedScopedId stopId, boolean checkParentStop) {
    Stop stop = graph.index.getStopForId(stopId);
    if (stop == null) {
        return new ArrayList<>();
    }
    Collection<TransitAlert> alertsForStop = graph.getTransitAlertService().getStopAlerts(stopId);
    if (checkParentStop) {
        if (alertsForStop == null) {
            alertsForStop = new HashSet<>();
        }
        if (stop.isPartOfStation()) {
            // Also check parent
            Collection<TransitAlert> parentStopAlerts = graph.getTransitAlertService().getStopAlerts(stop.getParentStation().getId());
            if (parentStopAlerts != null) {
                alertsForStop.addAll(parentStopAlerts);
            }
        }
    // TODO SIRI: Add support for fetching alerts attached to MultiModal-stops
    // if (stop.getMultiModalStation() != null) {
    // //Also check multimodal parent
    // FeedScopedId multimodalStopId = new FeedScopedId(stopId.getAgencyId(), stop.getMultiModalStation());
    // Collection<AlertPatch> multimodalStopAlerts = graph.index.getAlertsForStopId(multimodalStopId);
    // if (multimodalStopAlerts != null) {
    // alertsForStop.addAll(multimodalStopAlerts);
    // }
    // }
    }
    return alertsForStop;
}
Also used : TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList)

Aggregations

Stop (org.opentripplanner.model.Stop)73 FeedScopedId (org.opentripplanner.model.FeedScopedId)25 ArrayList (java.util.ArrayList)24 TripPattern (org.opentripplanner.model.TripPattern)24 Trip (org.opentripplanner.model.Trip)21 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 RoutingService (org.opentripplanner.routing.RoutingService)13 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)13 HashSet (java.util.HashSet)12 Station (org.opentripplanner.model.Station)12 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)11 List (java.util.List)10 Test (org.junit.Test)8 Route (org.opentripplanner.model.Route)8 StopTime (org.opentripplanner.model.StopTime)8 Collectors (java.util.stream.Collectors)7 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ApiStop (org.opentripplanner.api.model.ApiStop)7 TripTimeShort (org.opentripplanner.model.TripTimeShort)7