use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method getPatternForTripId.
/**
* Retrieve a trip pattern given a feed id and trip id.
*
* @param feedId feed id for the trip id
* @param tripId trip id without agency
* @return trip pattern or null if no trip pattern was found
*/
private TripPattern getPatternForTripId(String feedId, String tripId) {
Trip trip = routingService.getTripForId().get(new FeedScopedId(feedId, tripId));
TripPattern pattern = routingService.getPatternForTrip().get(trip);
return pattern;
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class TripPatternCache method getOrCreateTripPattern.
/**
* Get cached trip pattern or create one if it doesn't exist yet. If a trip pattern is created, vertices
* and edges for this trip pattern are also created in the graph.
*
* @param stopPattern stop pattern to retrieve/create trip pattern
* @param trip the trip the new trip pattern will be created for
* @param graph graph to add vertices and edges in case a new trip pattern will be created
* @return cached or newly created trip pattern
*/
public synchronized TripPattern getOrCreateTripPattern(@NotNull final StopPattern stopPattern, @NotNull final Trip trip, @NotNull final Graph graph) {
Route route = trip.getRoute();
// Check cache for trip pattern
TripPattern tripPattern = cache.get(stopPattern);
// Create TripPattern if it doesn't exist yet
if (tripPattern == null) {
tripPattern = new TripPattern(route, stopPattern);
// Generate unique code for trip pattern
tripPattern.setId(new FeedScopedId(tripPattern.getFeedId(), generateUniqueTripPatternCode(tripPattern)));
// Create an empty bitset for service codes (because the new pattern does not contain any trips)
tripPattern.setServiceCodes(graph.getServiceCodes());
// Finish scheduled time table
tripPattern.scheduledTimetable.finish();
TripPattern originalTripPattern = graph.index.getPatternForTrip().get(trip);
// Copy information from the TripPattern this is replacing
if (originalTripPattern != null) {
tripPattern.setHopGeometriesFromPattern(originalTripPattern);
}
// Add pattern to cache
cache.put(stopPattern, tripPattern);
}
return tripPattern;
}
use of org.opentripplanner.model.TripPattern 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);
}
}
}
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class RaptorPathToItineraryMapper method extractTransitLegCoordinates.
private List<Coordinate> extractTransitLegCoordinates(TransitPathLeg<TripSchedule> pathLeg) {
List<Coordinate> transitLegCoordinates = new ArrayList<>();
TripPattern tripPattern = pathLeg.trip().getOriginalTripPattern();
TripSchedule tripSchedule = pathLeg.trip();
boolean boarded = false;
for (int j = 0; j < tripPattern.stopPattern.stops.length; j++) {
int currentStopIndex = transitLayer.getStopIndex().indexByStop.get(tripPattern.getStop(j));
if (boarded) {
transitLegCoordinates.addAll(Arrays.asList(tripPattern.getHopGeometry(j - 1).getCoordinates()));
}
if (!boarded && tripSchedule.departure(j) == pathLeg.fromTime() && currentStopIndex == pathLeg.fromStop()) {
boarded = true;
}
if (boarded && tripSchedule.arrival(j) == pathLeg.toTime() && currentStopIndex == pathLeg.toStop()) {
break;
}
}
return transitLegCoordinates;
}
use of org.opentripplanner.model.TripPattern 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;
}
Aggregations