// Determine the set of pathway/transfer destinations
Set<TransitStop> pathwayDestinations = new HashSet<TransitStop>();
for (Edge e : ts.getOutgoing()) {
if (e instanceof PathwayEdge || e instanceof SimpleTransfer) {
if (e.getToVertex() instanceof TransitStop) {
TransitStop to = (TransitStop) e.getToVertex();
pathwayDestinations.add(to);
}
}
}
int n = 0;
RoutingRequest routingRequest = new RoutingRequest(TraverseMode.WALK);
routingRequest.clampInitialWait = (0L);
routingRequest.setRoutingContext(graph, ts, null);
routingRequest.rctx.pathParsers = parser;
ShortestPathTree spt = earliestArrivalSPTService.getShortestPathTree(routingRequest);
if (spt != null) {
for (State state : spt.getAllStates()) {
Vertex vertex = state.getVertex();
if (ts == vertex) continue;
if (vertex instanceof TransitStop) {
TransitStop other = (TransitStop) vertex;
if (!other.isStreetLinkable())
continue;
if (pathwayDestinations.contains(other)) {
LOG.trace("Skipping '{}', {}, already connected.", other.getStop(),
other);
continue;
}
double distance = 0.0;
GraphPath graphPath = new GraphPath(state, false);
CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence();
for (Edge edge : graphPath.edges) {
if (edge instanceof StreetEdge) {
LineString geometry = edge.getGeometry();
if (geometry != null) {
if (coordinates.size() == 0) {
coordinates.extend(geometry.getCoordinates());
} else {
coordinates.extend(geometry.getCoordinates(), 1);
}
}
distance += edge.getDistance();
}
}
if (coordinates.size() < 2) { // Otherwise the walk step generator breaks.
ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>(2);
coordinateList.add(graphPath.states.get(1).getVertex().getCoordinate());
State lastState = graphPath.states.getLast().getBackState();
coordinateList.add(lastState.getVertex().getCoordinate());
coordinates = new CoordinateArrayListSequence(coordinateList);
}
LineString geometry = geometryFactory.createLineString(new
PackedCoordinateSequence.Double(coordinates.toCoordinateArray()));
LOG.trace(" to stop: '{}' {} ({}m) [{}]", other.getStop(), other, distance, geometry);
new SimpleTransfer(ts, other, distance, geometry);
n++;
}
}
}