use of org.opentripplanner.extra_graph.EdgesForRoute in project OpenTripPlanner by opentripplanner.
the class BusRouteStreetMatcher method buildGraph.
/*
The "extra" parameter is a mechanism for passing arbitrary things between graph builder modules.
Whether or not this is a good idea is open to debate, but that's what it is.
An EdgesForRoute instance is generated by MapBuilder and StreetMatcher, then retrieved later by the
NetworkLinkerLibrary later (actually in LinkRequests).
*/
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
// Mapbuilder needs transit index
graph.index(new DefaultStreetVertexIndexFactory());
StreetMatcher matcher = new StreetMatcher(graph);
EdgesForRoute edgesForRoute = new EdgesForRoute();
extra.put(EdgesForRoute.class, edgesForRoute);
log.info("Finding corresponding street edges for trip patterns...");
// Why do we need to iterate over the routes? Why not just patterns?
for (Route route : graph.index.routeForId.values()) {
for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
if (pattern.mode == TraverseMode.BUS) {
/* we can only match geometry to streets on bus routes */
log.debug("Matching {}", pattern);
// that is why pattern.geometry is null in that case
if (pattern.geometry == null) {
continue;
}
List<Edge> edges = matcher.match(pattern.geometry);
if (edges == null || edges.isEmpty()) {
log.warn("Could not match to street network: {}", pattern);
continue;
}
List<Coordinate> coordinates = new ArrayList<Coordinate>();
for (Edge e : edges) {
coordinates.addAll(Arrays.asList(e.getGeometry().getCoordinates()));
edgesForRoute.edgesForRoute.put(route, e);
}
Coordinate[] coordinateArray = new Coordinate[coordinates.size()];
LineString ls = GeometryUtils.getGeometryFactory().createLineString(coordinates.toArray(coordinateArray));
// Replace the pattern's geometry from GTFS with that of the equivalent OSM edges.
pattern.geometry = ls;
}
}
}
}
Aggregations