use of org.opentripplanner.transit.raptor.api.path.EgressPathLeg in project OpenTripPlanner by opentripplanner.
the class ForwardPathMapper method createEgressPathLeg.
private EgressPathLeg<T> createEgressPathLeg(DestinationArrival<T> destinationArrival) {
RaptorTransfer egress = destinationArrival.egressLeg().egress();
int departureTime = destinationArrival.arrivalTime() - egress.durationInSeconds();
return new EgressPathLeg<>(egress, destinationArrival.previous().stop(), departureTime, destinationArrival.arrivalTime());
}
use of org.opentripplanner.transit.raptor.api.path.EgressPathLeg in project OpenTripPlanner by opentripplanner.
the class ItineraryMapper method createItinerary.
private Itinerary createItinerary(Path<TripSchedule> path, StopAtDistance accessPath, StopAtDistance egressPath) {
if (path == null) {
return null;
}
Itinerary itinerary = new Itinerary();
itinerary.walkDistance = 0.0;
itinerary.transitTime = 0;
itinerary.waitingTime = 0;
itinerary.weight = path.cost();
int numberOfTransits = 0;
// Access leg
Leg leg = new Leg();
AccessPathLeg<TripSchedule> accessLeg = path.accessLeg();
leg.startTime = accessLeg.fromTime();
leg.endTime = accessLeg.toTime();
leg.from = request.tc().fromPlace;
leg.to = request.tc().toPlace;
leg.mode = WALK;
leg.distance = accessPath.distance;
itinerary.addLeg(leg);
PathLeg<TripSchedule> pathLeg = accessLeg.nextLeg();
int previousArrivalTime = -1;
while (pathLeg.isTransitLeg() || pathLeg.isTransferLeg()) {
leg = new Leg();
// Transfer leg if present
if (pathLeg.isTransferLeg()) {
TransferPathLeg<?> it = pathLeg.asTransferLeg();
previousArrivalTime = it.toTime();
leg.startTime = it.fromTime();
leg.endTime = previousArrivalTime;
leg.mode = WALK;
leg.from = mapToPlace(it.fromStop());
leg.to = mapToPlace(it.toStop());
// distanceMMToMeters (transferPath.getDistance());
leg.distance = -1.0;
} else {
// Transit leg
TransitPathLeg<TripSchedule> it = pathLeg.asTransitLeg();
itinerary.transitTime += it.toTime() - it.fromTime();
itinerary.waitingTime += it.fromTime() - previousArrivalTime;
previousArrivalTime = it.toTime();
++numberOfTransits;
leg.distance = 0.0;
TripSchedule tripSchedule = it.trip();
TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
Route routeInfo = tripPattern.route;
leg.from = mapToPlace(it.fromStop());
leg.to = mapToPlace(it.toStop());
leg.route = routeInfo.getShortName();
leg.agencyName = routeInfo.getAgency().getName();
leg.tripShortName = tripSchedule.getOriginalTripPattern().name;
leg.agencyId = routeInfo.getAgency().getId();
leg.routeShortName = routeInfo.getShortName();
leg.routeLongName = routeInfo.getLongName();
leg.mode = TraverseMode.fromTransitMode(tripSchedule.getOriginalTripPattern().getMode());
leg.startTime = it.fromTime();
leg.endTime = it.toTime();
}
itinerary.addLeg(leg);
pathLeg = pathLeg.nextLeg();
}
// Egress leg
leg = new Leg();
EgressPathLeg<TripSchedule> egressLeg = pathLeg.asEgressLeg();
leg.startTime = egressLeg.fromTime();
leg.endTime = egressLeg.toTime();
leg.from = mapToPlace(egressLeg.fromStop());
leg.to = request.tc().toPlace;
leg.mode = WALK;
leg.distance = egressPath.distance;
itinerary.addLeg(leg);
itinerary.startTime = itinerary.legs.get(0).startTime;
itinerary.endTime = leg.endTime;
itinerary.duration = itinerary.endTime - itinerary.startTime;
// The number of transfers is the number of transits minus one, we can NOT count the number of Transfers
// in the path or itinerary, because transfers at the same stop does not produce a transfer object, just two
// transits following each other.
itinerary.transfers = numberOfTransits - 1;
return itinerary;
}
use of org.opentripplanner.transit.raptor.api.path.EgressPathLeg in project OpenTripPlanner by opentripplanner.
the class ReversePathMapper method mapToEgressLeg.
private EgressPathLeg<T> mapToEgressLeg(ArrivalView<T> accessArrival) {
RaptorTransfer egress = accessArrival.accessLeg().access();
int targetDepartureTime = accessArrival.arrivalTime();
int targetArrivalTime = accessArrival.arrivalTime() + egress.durationInSeconds();
// No need to time-shift the egress leg, this is done when stopArrival is created
return new EgressPathLeg<>(egress, accessArrival.stop(), targetDepartureTime, targetArrivalTime);
}
use of org.opentripplanner.transit.raptor.api.path.EgressPathLeg in project OpenTripPlanner by opentripplanner.
the class RaptorPathToItineraryMapper method createItinerary.
public Itinerary createItinerary(Path<TripSchedule> path) {
List<Leg> legs = new ArrayList<>();
// Map access leg
mapAccessLeg(legs, path.accessLeg());
// TODO: Add back this code when PathLeg interface contains object references
PathLeg<TripSchedule> pathLeg = path.accessLeg().nextLeg();
boolean firstLeg = true;
while (!pathLeg.isEgressLeg()) {
// Map transit leg
if (pathLeg.isTransitLeg()) {
Leg transitLeg = mapTransitLeg(request, pathLeg.asTransitLeg(), firstLeg);
firstLeg = false;
legs.add(transitLeg);
}
// Map transfer leg
if (pathLeg.isTransferLeg()) {
mapTransferLeg(legs, pathLeg.asTransferLeg());
}
pathLeg = pathLeg.nextLeg();
}
// Map egress leg
EgressPathLeg<TripSchedule> egressPathLeg = pathLeg.asEgressLeg();
mapEgressLeg(legs, egressPathLeg);
propagateStopPlaceNamesToWalkingLegs(legs);
Itinerary itinerary = new Itinerary(legs);
// Map general itinerary fields
itinerary.generalizedCost = path.cost();
itinerary.nonTransitLimitExceeded = itinerary.nonTransitDistanceMeters > request.maxWalkDistance;
return itinerary;
}
Aggregations