Search in sources :

Example 1 with StreetTransitLink

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());
}
Also used : StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink)

Example 2 with StreetTransitLink

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)));
            }
        }
    }
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ArrayList(java.util.ArrayList) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 3 with StreetTransitLink

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;
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 4 with StreetTransitLink

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;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Router(org.opentripplanner.standalone.Router) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 5 with StreetTransitLink

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();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) STRtree(com.vividsolutions.jts.index.strtree.STRtree) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) Envelope(com.vividsolutions.jts.geom.Envelope) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge)

Aggregations

StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)10 Edge (org.opentripplanner.routing.graph.Edge)6 Vertex (org.opentripplanner.routing.graph.Vertex)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)4 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)4 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)3 SimpleTransfer (org.opentripplanner.routing.edgetype.SimpleTransfer)3 Graph (org.opentripplanner.routing.graph.Graph)3 Envelope (com.vividsolutions.jts.geom.Envelope)2 LineString (com.vividsolutions.jts.geom.LineString)2 State (org.opentripplanner.routing.core.State)2 TransitStopStreetVertex (org.opentripplanner.routing.vertextype.TransitStopStreetVertex)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)1 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 Point (com.vividsolutions.jts.geom.Point)1