Search in sources :

Example 46 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class StreetVertexIndexServiceImpl method postSetup.

@SuppressWarnings("rawtypes")
private void postSetup() {
    for (Vertex gv : graph.getVertices()) {
        Vertex v = gv;
        /*
             * We add all edges with geometry, skipping transit, filtering them out after. We do not
             * index transit edges as we do not need them and some GTFS do not have shape data, so
             * long straight lines between 2 faraway stations will wreck performance on a hash grid
             * spatial index.
             * 
             * If one need to store transit edges in the index, we could improve the hash grid
             * rasterizing splitting long segments.
             */
        for (Edge e : gv.getOutgoing()) {
            if (e instanceof PatternEdge || e instanceof SimpleTransfer)
                continue;
            LineString geometry = e.getGeometry();
            if (geometry == null) {
                continue;
            }
            Envelope env = geometry.getEnvelopeInternal();
            if (edgeTree instanceof HashGridSpatialIndex)
                ((HashGridSpatialIndex) edgeTree).insert(geometry, e);
            else
                edgeTree.insert(env, e);
        }
        if (v instanceof TransitStop) {
            Envelope env = new Envelope(v.getCoordinate());
            transitStopTree.insert(env, v);
        }
        Envelope env = new Envelope(v.getCoordinate());
        verticesTree.insert(env, v);
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) SampleVertex(org.opentripplanner.routing.vertextype.SampleVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) HashGridSpatialIndex(org.opentripplanner.common.geometry.HashGridSpatialIndex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) LineString(com.vividsolutions.jts.geom.LineString) Envelope(com.vividsolutions.jts.geom.Envelope) Edge(org.opentripplanner.routing.graph.Edge)

Example 47 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TestHopFactory method testBoardAlight.

public void testBoardAlight() throws Exception {
    Vertex stop_a = graph.getVertex(feedId + ":A_depart");
    Vertex stop_b_depart = graph.getVertex(feedId + ":B_depart");
    assertEquals(1, stop_a.getDegreeOut());
    assertEquals(3, stop_b_depart.getDegreeOut());
    for (Edge e : stop_a.getOutgoing()) {
        assertEquals(TransitBoardAlight.class, e.getClass());
        assertTrue(((TransitBoardAlight) e).boarding);
    }
    // TODO: could this ever be a PatternAlight? I think not.
    TransitBoardAlight pb = (TransitBoardAlight) stop_a.getOutgoing().iterator().next();
    Vertex journey_a_1 = pb.getToVertex();
    assertEquals(1, journey_a_1.getDegreeIn());
    for (Edge e : journey_a_1.getOutgoing()) {
        if (e.getToVertex() instanceof TransitStop) {
            assertEquals(TransitBoardAlight.class, e.getClass());
            assertTrue(((TransitBoardAlight) e).boarding);
        } else {
            assertEquals(PatternHop.class, e.getClass());
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) Edge(org.opentripplanner.routing.graph.Edge)

Example 48 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method setUp.

public void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    feedId = context.getFeedId().getId();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    String[] stops = { feedId + ":A", feedId + ":B", feedId + ":C", feedId + ":D", feedId + ":E", feedId + ":entrance_a", feedId + ":entrance_b" };
    for (int i = 0; i < stops.length; ++i) {
        TransitStop stop = (TransitStop) (graph.getVertex(stops[i]));
        IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
        IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001);
        StreetEdge street1 = new StreetEdge(front, back, GeometryUtils.makeLineString(stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false);
        StreetEdge street2 = new StreetEdge(back, front, GeometryUtils.makeLineString(stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true);
    }
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    // Linkers aren't run otherwise
    graph.hasStreets = true;
    graph.hasTransit = true;
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) File(java.io.File) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule)

Example 49 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class GraphIndexTest method testSpatialIndex.

public void testSpatialIndex() {
    String feedId = graph.getFeedIds().iterator().next();
    Stop stopJ = graph.index.stopForId.get(new AgencyAndId(feedId, "J"));
    Stop stopL = graph.index.stopForId.get(new AgencyAndId(feedId, "L"));
    Stop stopM = graph.index.stopForId.get(new AgencyAndId(feedId, "M"));
    TransitStop stopvJ = graph.index.stopVertexForStop.get(stopJ);
    TransitStop stopvL = graph.index.stopVertexForStop.get(stopL);
    TransitStop stopvM = graph.index.stopVertexForStop.get(stopM);
    // There are a two other stops within 100 meters of stop J.
    Envelope env = new Envelope(new Coordinate(stopJ.getLon(), stopJ.getLat()));
    env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(100, stopJ.getLat()), SphericalDistanceLibrary.metersToDegrees(100));
    List<TransitStop> stops = graph.index.stopSpatialIndex.query(env);
    assertTrue(stops.contains(stopvJ));
    assertTrue(stops.contains(stopvL));
    assertTrue(stops.contains(stopvM));
    // Query can overselect
    assertTrue(stops.size() >= 3);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Coordinate(com.vividsolutions.jts.geom.Coordinate) Envelope(com.vividsolutions.jts.geom.Envelope)

Aggregations

TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Stop (org.onebusaway.gtfs.model.Stop)20 Vertex (org.opentripplanner.routing.graph.Vertex)18 Edge (org.opentripplanner.routing.graph.Edge)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)11 Graph (org.opentripplanner.routing.graph.Graph)10 Envelope (com.vividsolutions.jts.geom.Envelope)8 LineString (com.vividsolutions.jts.geom.LineString)8 ArrayList (java.util.ArrayList)8 State (org.opentripplanner.routing.core.State)8 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 Agency (org.onebusaway.gtfs.model.Agency)7 Trip (org.onebusaway.gtfs.model.Trip)7 SimpleTransfer (org.opentripplanner.routing.edgetype.SimpleTransfer)7 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)7 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)7 Route (org.onebusaway.gtfs.model.Route)6