use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class GraphPathToTripPlanConverter method addModeAndAlerts.
/**
* Add mode and alerts fields to a {@link Leg}.
*
* @param leg The leg to add the mode and alerts to
* @param states The states that go with the leg
*/
private static void addModeAndAlerts(Graph graph, Leg leg, State[] states, boolean disableAlertFiltering, Locale requestedLocale) {
for (State state : states) {
TraverseMode mode = state.getBackMode();
Set<Alert> alerts = graph.streetNotesService.getNotes(state);
Edge edge = state.getBackEdge();
if (mode != null) {
leg.mode = mode.toString();
}
if (alerts != null) {
for (Alert alert : alerts) {
leg.addAlert(alert, requestedLocale);
}
}
for (AlertPatch alertPatch : graph.getAlertPatches(edge)) {
if (disableAlertFiltering || alertPatch.displayDuring(state)) {
if (alertPatch.hasTrip()) {
// this leg.
if (alertPatch.getTrip().equals(leg.tripId)) {
leg.addAlert(alertPatch.getAlert(), requestedLocale);
}
} else {
// If we are not matching a particular trip add all known alerts for this trip pattern.
leg.addAlert(alertPatch.getAlert(), requestedLocale);
}
}
}
}
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class GraphPathToTripPlanConverter method calculateElevations.
/**
* Calculate the elevationGained and elevationLost fields of an {@link Itinerary}.
*
* @param itinerary The itinerary to calculate the elevation changes for
* @param edges The edges that go with the itinerary
*/
private static void calculateElevations(Itinerary itinerary, Edge[] edges) {
for (Edge edge : edges) {
if (!(edge instanceof StreetEdge))
continue;
StreetEdge edgeWithElevation = (StreetEdge) edge;
PackedCoordinateSequence coordinates = edgeWithElevation.getElevationProfile();
if (coordinates == null)
continue;
// TODO Check the test below, AFAIU current elevation profile has 3 dimensions.
if (coordinates.getDimension() != 2)
continue;
for (int i = 0; i < coordinates.size() - 1; i++) {
double change = coordinates.getOrdinate(i + 1, 1) - coordinates.getOrdinate(i, 1);
if (change > 0) {
itinerary.elevationGained += change;
} else if (change < 0) {
itinerary.elevationLost -= change;
}
}
}
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class GraphPathToTripPlanConverter method generateLeg.
/**
* Generate one leg of an itinerary from a {@link State} array.
*
* @param states The array of states to base the leg on
* @param showIntermediateStops Whether to include intermediate stops in the leg or not
* @return The generated leg
*/
private static Leg generateLeg(Graph graph, State[] states, boolean showIntermediateStops, boolean disableAlertFiltering, Locale requestedLocale) {
Leg leg = new Leg();
Edge[] edges = new Edge[states.length - 1];
leg.startTime = makeCalendar(states[0]);
leg.endTime = makeCalendar(states[states.length - 1]);
// Calculate leg distance and fill array of edges
leg.distance = 0.0;
for (int i = 0; i < edges.length; i++) {
edges[i] = states[i + 1].getBackEdge();
leg.distance += edges[i].getDistance();
}
TimeZone timeZone = leg.startTime.getTimeZone();
leg.agencyTimeZoneOffset = timeZone.getOffset(leg.startTime.getTimeInMillis());
addTripFields(leg, states, requestedLocale);
addPlaces(leg, states, edges, showIntermediateStops, requestedLocale);
CoordinateArrayListSequence coordinates = makeCoordinates(edges);
Geometry geometry = GeometryUtils.getGeometryFactory().createLineString(coordinates);
leg.legGeometry = PolylineEncoder.createEncodings(geometry);
leg.interlineWithPreviousLeg = states[0].getBackEdge() instanceof PatternInterlineDwell;
addFrequencyFields(states, leg);
leg.rentedBike = states[0].isBikeRenting() && states[states.length - 1].isBikeRenting();
addModeAndAlerts(graph, leg, states, disableAlertFiltering, requestedLocale);
if (leg.isTransitLeg())
addRealTimeData(leg, states);
return leg;
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class GraphPathToTripPlanConverter method createWalkStep.
private static WalkStep createWalkStep(Graph graph, State s, Locale wantedLocale) {
Edge en = s.getBackEdge();
WalkStep step;
step = new WalkStep();
step.streetName = en.getName(wantedLocale);
step.lon = en.getFromVertex().getX();
step.lat = en.getFromVertex().getY();
step.elevation = encodeElevationProfile(s.getBackEdge(), 0, s.getOptions().geoidElevation ? -graph.ellipsoidToGeoidDifference : 0);
step.bogusName = en.hasBogusName();
step.addAlerts(graph.streetNotesService.getNotes(s), wantedLocale);
step.angle = DirectionUtils.getFirstAngle(s.getBackEdge().getGeometry());
if (s.getBackEdge() instanceof AreaEdge) {
step.area = true;
}
return step;
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class GraphCoherencyCheckerModule method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
boolean coherent = true;
LOG.info("checking graph coherency...");
for (Vertex v : graph.getVertices()) {
if (v.getOutgoing().isEmpty() && v.getIncoming().isEmpty()) {
LOG.error("vertex {} has no edges", v);
coherent = false;
}
for (Edge e : v.getOutgoing()) {
if (e.getFromVertex() != v) {
LOG.error("outgoing edge of {}: from vertex {} does not match", v, e);
coherent = false;
}
if (e.getToVertex() == null) {
LOG.error("outgoing edge has no to vertex {}", e);
coherent = false;
}
}
for (Edge e : v.getIncoming()) {
if (e.getFromVertex() == null) {
LOG.error("incoming edge has no from vertex {}", e);
coherent = false;
}
if (e.getToVertex() != v) {
LOG.error("incoming edge of {}: to vertex {} does not match", v, e);
coherent = false;
}
}
}
LOG.info("edge lists and from/to members are {}coherent.", coherent ? "" : "not ");
}
Aggregations