use of org.opentripplanner.routing.edgetype.PathwayEdge in project OpenTripPlanner by opentripplanner.
the class DirectTransferGenerator method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
/* Initialize graph index which is needed by the nearby stop finder. */
if (graph.index == null) {
graph.index = new GraphIndex(graph);
}
/* The linker will use streets if they are available, or straight-line distance otherwise. */
NearbyStopFinder nearbyStopFinder = new NearbyStopFinder(graph, radiusMeters);
if (nearbyStopFinder.useStreets) {
LOG.info("Creating direct transfer edges between stops using the street network from OSM...");
} else {
LOG.info("Creating direct transfer edges between stops using straight line distance (not streets)...");
}
int nTransfersTotal = 0;
int nLinkableStops = 0;
for (TransitStop ts0 : Iterables.filter(graph.getVertices(), TransitStop.class)) {
/* Skip stops that are entrances to stations or whose entrances are coded separately */
if (!ts0.isStreetLinkable())
continue;
if (++nLinkableStops % 1000 == 0) {
LOG.info("Linked {} stops", nLinkableStops);
}
LOG.debug("Linking stop '{}' {}", ts0.getStop(), ts0);
/* Determine the set of stops that are already reachable via other pathways or transfers */
Set<TransitStop> pathwayDestinations = new HashSet<TransitStop>();
for (Edge e : ts0.getOutgoing()) {
if (e instanceof PathwayEdge || e instanceof SimpleTransfer) {
if (e.getToVertex() instanceof TransitStop) {
TransitStop to = (TransitStop) e.getToVertex();
pathwayDestinations.add(to);
}
}
}
/* Make transfers to each nearby stop that is the closest stop on some trip pattern. */
int n = 0;
for (NearbyStopFinder.StopAtDistance sd : nearbyStopFinder.findNearbyStopsConsideringPatterns(ts0)) {
/* Skip the origin stop, loop transfers are not needed. */
if (sd.tstop == ts0 || pathwayDestinations.contains(sd.tstop))
continue;
new SimpleTransfer(ts0, sd.tstop, sd.dist, sd.geom, sd.edges);
n += 1;
}
LOG.debug("Linked stop {} to {} nearby stops on other patterns.", ts0.getStop(), n);
if (n == 0) {
LOG.debug(graph.addBuilderAnnotation(new StopNotLinkedForTransfers(ts0)));
}
nTransfersTotal += n;
}
LOG.info("Done connecting stops to one another. Created a total of {} transfers from {} stops.", nTransfersTotal, nLinkableStops);
graph.hasDirectTransfers = true;
}
use of org.opentripplanner.routing.edgetype.PathwayEdge in project OpenTripPlanner by opentripplanner.
the class GTFSPatternHopFactory method loadPathways.
private void loadPathways(Graph graph) {
for (Pathway pathway : _dao.getAllPathways()) {
Vertex fromVertex = context.stationStopNodes.get(pathway.getFromStop());
Vertex toVertex = context.stationStopNodes.get(pathway.getToStop());
if (pathway.isWheelchairTraversalTimeSet()) {
new PathwayEdge(fromVertex, toVertex, pathway.getTraversalTime(), pathway.getWheelchairTraversalTime());
} else {
new PathwayEdge(fromVertex, toVertex, pathway.getTraversalTime());
}
}
}
use of org.opentripplanner.routing.edgetype.PathwayEdge in project OpenTripPlanner by opentripplanner.
the class ShowGraph method buildSpatialIndex.
/*
* Iterate through all vertices and their (outgoing) edges. If they are of 'interesting' types,
* add them to the corresponding spatial index.
*/
public synchronized void buildSpatialIndex() {
vertexIndex = new STRtree();
edgeIndex = new STRtree();
Envelope env;
// int xminx, xmax, ymin, ymax;
for (Vertex v : graph.getVertices()) {
Coordinate c = v.getCoordinate();
env = new Envelope(c);
vertexIndex.insert(env, v);
for (Edge e : v.getOutgoing()) {
if (e.getGeometry() == null)
continue;
if (e instanceof PatternEdge || e instanceof StreetTransitLink || e instanceof StreetEdge || e instanceof PathwayEdge || e instanceof SimpleTransfer) {
env = e.getGeometry().getEnvelopeInternal();
edgeIndex.insert(env, e);
}
}
}
vertexIndex.build();
edgeIndex.build();
}
use of org.opentripplanner.routing.edgetype.PathwayEdge in project OpenTripPlanner by opentripplanner.
the class UnconnectedStop method fulfillDemands.
/**
* @retrun return true if the stop is not connected to any street
*/
@Override
public boolean fulfillDemands(TransitStop ts, Graph graph) {
List<Edge> outgoingStreets = ts.getOutgoingStreetEdges();
boolean hasStreetLink = false;
for (Edge e : ts.getIncoming()) {
if (e instanceof StreetTransitLink || e instanceof PathwayEdge) {
hasStreetLink = true;
break;
}
}
if (!hasStreetLink) {
// TODO: see what if there is incoming and not outgoing
for (Edge e : ts.getOutgoing()) {
if (e instanceof StreetTransitLink) {
hasStreetLink = true;
break;
}
}
}
return !(hasStreetLink || (outgoingStreets.size() > 0));
}
use of org.opentripplanner.routing.edgetype.PathwayEdge in project OpenTripPlanner by opentripplanner.
the class ShowGraph method findVisibleElements.
@SuppressWarnings("unchecked")
private synchronized void findVisibleElements() {
visibleVertices = (List<Vertex>) vertexIndex.query(modelBounds);
visibleStreetEdges.clear();
visibleLinkEdges.clear();
visibleTransitEdges.clear();
for (Edge de : (Iterable<Edge>) edgeIndex.query(modelBounds)) {
if (de instanceof PatternEdge) {
visibleTransitEdges.add(de);
} else if (de instanceof PathwayEdge || de instanceof StreetTransitLink || de instanceof SimpleTransfer) {
visibleLinkEdges.add(de);
} else if (de instanceof StreetEdge) {
visibleStreetEdges.add(de);
}
}
}
Aggregations