use of org.opentripplanner.routing.edgetype.StreetTransitLink in project OpenTripPlanner by opentripplanner.
the class SimpleStreetSplitter method makeTransitLinkEdges.
/**
* Make street transit link edges, unless they already exist.
*/
private void makeTransitLinkEdges(TransitStop tstop, StreetVertex v) {
if (!destructiveSplitting) {
throw new RuntimeException("Transitedges are created with non destructive splitting!");
}
// this can happen if we link to duplicate ways that have the same start/end vertices.
for (StreetTransitLink e : Iterables.filter(tstop.getOutgoing(), StreetTransitLink.class)) {
if (e.getToVertex() == v)
return;
}
new StreetTransitLink(tstop, v, tstop.hasWheelchairEntrance());
new StreetTransitLink(v, tstop, tstop.hasWheelchairEntrance());
}
use of org.opentripplanner.routing.edgetype.StreetTransitLink in project OpenTripPlanner by opentripplanner.
the class TransitToTaggedStopsModule method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
LOG.info("Linking transit stops to tagged bus stops...");
index = new StreetVertexIndexServiceImpl(graph);
// iterate over a copy of vertex list because it will be modified
ArrayList<Vertex> vertices = new ArrayList<>();
vertices.addAll(graph.getVertices());
for (TransitStop ts : Iterables.filter(vertices, TransitStop.class)) {
// if the street is already linked there is no need to linked it again,
// could happened if using the prune isolated island
boolean alreadyLinked = false;
for (Edge e : ts.getOutgoing()) {
if (e instanceof StreetTransitLink) {
alreadyLinked = true;
break;
}
}
if (alreadyLinked)
continue;
// entrances
if (ts.isEntrance() || !ts.hasEntrances()) {
boolean wheelchairAccessible = ts.hasWheelchairEntrance();
if (!connectVertexToStop(ts, wheelchairAccessible)) {
LOG.debug("Could not connect " + ts.getStopCode() + " at " + ts.getCoordinate().toString());
// LOG.warn(graph.addBuilderAnnotation(new StopUnlinked(ts)));
}
}
}
}
use of org.opentripplanner.routing.edgetype.StreetTransitLink in project OpenTripPlanner by opentripplanner.
the class TransitToTaggedStopsModule method connectVertexToStop.
private boolean connectVertexToStop(TransitStop ts, boolean wheelchairAccessible) {
String stopCode = ts.getStopCode();
if (stopCode == null) {
return false;
}
Envelope envelope = new Envelope(ts.getCoordinate());
double xscale = Math.cos(ts.getCoordinate().y * Math.PI / 180);
envelope.expandBy(searchRadiusLat / xscale, searchRadiusLat);
Collection<Vertex> vertices = index.getVerticesForEnvelope(envelope);
// in their ref= tag that matches the GTFS stop code of this TransitStop.
for (Vertex v : vertices) {
if (!(v instanceof TransitStopStreetVertex)) {
continue;
}
TransitStopStreetVertex tsv = (TransitStopStreetVertex) v;
// Only use stop codes for linking TODO: find better method to connect stops without stop code
if (tsv.stopCode != null && tsv.stopCode.equals(stopCode)) {
new StreetTransitLink(ts, tsv, wheelchairAccessible);
new StreetTransitLink(tsv, ts, wheelchairAccessible);
LOG.debug("Connected " + ts.toString() + " to " + tsv.getLabel());
return true;
}
}
return false;
}
use of org.opentripplanner.routing.edgetype.StreetTransitLink in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makePoints.
/**
* @return a map from each vertex to minimum travel time over the course of the day.
*/
private Map<Vertex, Double> makePoints() throws Exception {
rangeCheckParameters();
request = buildRequest();
Router router = otpServer.getRouter(routerId);
Graph graph = router.graph;
// double speed = request.getWalkSpeed();
Coordinate originCoord = request.from.getCoordinate();
if (originCoord == null)
return null;
List<TransitStop> stops = graph.streetIndex.getNearbyTransitStops(originCoord, radiusMeters);
if (stops.isEmpty()) {
LOG.error("No stops found within {} meters.", radiusMeters);
return null;
}
if (shpName == null)
shpName = stops.get(0).getName().split(" ")[0];
StreetVertex origin = new IntersectionVertex(graph, "iso_temp", originCoord.x, originCoord.y);
for (TransitStop stop : stops) {
new StreetTransitLink(origin, stop, false);
LOG.debug("linked to stop {}", stop.getName());
}
request.setRoutingContext(graph, origin, null);
/* Make one request every M minutes over H hours */
int nRequests = (requestTimespanHours * 60) / requestSpacingMinutes;
request.clampInitialWait = (requestSpacingMinutes * 60);
Date date = request.getDateTime();
MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
for (int r = 0; r < nRequests; r++) {
request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
/* This could even be a good use for a generic SPT merging function */
for (State s : spt.getAllStates()) {
if (stopsOnly && !(s.getVertex() instanceof TransitStop))
continue;
points.putMin(s.getVertex(), (double) (s.getActiveTime()));
}
}
graph.removeVertexAndEdges(origin);
return points;
}
use of org.opentripplanner.routing.edgetype.StreetTransitLink 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();
}
Aggregations