Search in sources :

Example 1 with StreetVertexIndex

use of org.opentripplanner.routing.impl.StreetVertexIndex in project OpenTripPlanner by opentripplanner.

the class FlexLocationsToStreetEdgesMapper method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    if (graph.locationsById.isEmpty()) {
        return;
    }
    StreetVertexIndex streetIndex = new StreetVertexIndex(graph);
    for (FlexStopLocation flexStopLocation : graph.locationsById.values()) {
        for (Vertex vertx : streetIndex.getVerticesForEnvelope(flexStopLocation.getGeometry().getEnvelopeInternal())) {
            // Check that the vertex is connected to both driveable and walkable edges
            if (!(vertx instanceof StreetVertex)) {
                continue;
            }
            if (!((StreetVertex) vertx).isEligibleForCarPickupDropoff()) {
                continue;
            }
            // The street index overselects, so need to check for exact geometry inclusion
            Point p = GeometryUtils.getGeometryFactory().createPoint(vertx.getCoordinate());
            if (flexStopLocation.getGeometry().disjoint(p)) {
                continue;
            }
            StreetVertex streetVertex = (StreetVertex) vertx;
            if (streetVertex.flexStopLocations == null) {
                streetVertex.flexStopLocations = new HashSet<>();
            }
            streetVertex.flexStopLocations.add(flexStopLocation);
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) FlexStopLocation(org.opentripplanner.model.FlexStopLocation) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Point(org.locationtech.jts.geom.Point) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex)

Example 2 with StreetVertexIndex

use of org.opentripplanner.routing.impl.StreetVertexIndex in project OpenTripPlanner by opentripplanner.

the class StateEditorTest method testSetNonTransitOptionsFromState.

/**
 * Test update of non transit options.
 */
@Test
public final void testSetNonTransitOptionsFromState() {
    RoutingRequest request = new RoutingRequest();
    request.setMode(TraverseMode.CAR);
    request.parkAndRide = true;
    Graph graph = new Graph();
    graph.index = new GraphIndex(graph);
    graph.streetIndex = new StreetVertexIndex(graph);
    request.rctx = new RoutingContext(request, graph);
    State state = new State(request);
    state.stateData.carParked = true;
    state.stateData.bikeParked = true;
    state.stateData.usingRentedBike = false;
    state.stateData.nonTransitMode = TraverseMode.WALK;
    StateEditor se = new StateEditor(request, null);
    se.setNonTransitOptionsFromState(state);
    State updatedState = se.makeState();
    assertEquals(TraverseMode.WALK, updatedState.getNonTransitMode());
    assertEquals(true, updatedState.isCarParked());
    assertEquals(true, updatedState.isBikeParked());
    assertEquals(false, updatedState.isBikeRenting());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex) Test(org.junit.Test)

Example 3 with StreetVertexIndex

use of org.opentripplanner.routing.impl.StreetVertexIndex in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testBuildingAreas.

/**
 * This reads test file with area
 * and tests if it can be routed if visibility is used and if it isn't
 *
 * Routing needs to be successful in both options since without visibility calculation
 * area rings are used.
 * @param skipVisibility if true visibility calculations are skipped
 * @throws UnsupportedEncodingException
 */
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
    Graph graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.skipVisibility = skipVisibility;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.pbf").getFile(), "UTF-8"));
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(file, false);
    loader.setProvider(provider);
    loader.buildGraph(graph, extra);
    new StreetVertexIndex(graph);
    Router router = new Router(graph, RouterConfig.DEFAULT);
    router.startup();
    RoutingRequest request = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
    // This are vertices that can be connected only over edges on area (with correct permissions)
    // It tests if it is possible to route over area without visibility calculations
    Vertex bottomV = graph.getVertex("osm:node:580290955");
    Vertex topV = graph.getVertex("osm:node:559271124");
    request.setRoutingContext(router.graph, bottomV, topV);
    GraphPathFinder graphPathFinder = new GraphPathFinder(router);
    List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
    assertNotNull(pathList);
    assertFalse(pathList.isEmpty());
    for (GraphPath path : pathList) {
        assertFalse(path.states.isEmpty());
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GraphPath(org.opentripplanner.routing.spt.GraphPath) Router(org.opentripplanner.standalone.server.Router) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) Graph(org.opentripplanner.routing.graph.Graph) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) File(java.io.File) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex)

Example 4 with StreetVertexIndex

use of org.opentripplanner.routing.impl.StreetVertexIndex in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testStreetLocationFinder.

@Test
public void testStreetLocationFinder() {
    StreetVertexIndex finder = new StreetVertexIndex(graph);
    // test that the local stop finder finds stops
    GenericLocation loc = new GenericLocation(40.01, -74.005000001);
    assertTrue(finder.getNearbyTransitStops(loc.getCoordinate(), 100).size() > 0);
    // test that the closest vertex finder returns the closest vertex
    TemporaryStreetLocation some = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.00, -74.00), null, true);
    assertNotNull(some);
    // test that the closest vertex finder correctly splits streets
    TemporaryStreetLocation start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.01), null, false);
    assertNotNull(start);
    assertTrue("wheelchair accessibility is correctly set (splitting)", start.isWheelchairAccessible());
    Collection<Edge> edges = start.getOutgoing();
    assertEquals(2, edges.size());
    RoutingRequest biking = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
    TemporaryStreetLocation end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), biking, true);
    assertNotNull(end);
    edges = end.getIncoming();
    assertEquals(2, edges.size());
    // test that it is possible to travel between two splits on the same street
    RoutingRequest walking = new RoutingRequest(TraverseMode.WALK);
    start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.0), walking, false);
    end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), walking, true);
    assertNotNull(end);
    // The visibility for temp edges for start and end is set in the setRoutingContext call
    walking.setRoutingContext(graph, start, end);
    ShortestPathTree spt = aStar.getShortestPathTree(walking);
    GraphPath path = spt.getPath(end, false);
    for (State s : path.states) {
        assertFalse(s.getBackEdge() == top);
    }
    walking.cleanup();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) GenericLocation(org.opentripplanner.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex) Test(org.junit.Test)

Example 5 with StreetVertexIndex

use of org.opentripplanner.routing.impl.StreetVertexIndex in project OpenTripPlanner by opentripplanner.

the class TransitToTaggedStopsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    LOG.info("Linking transit stops to tagged bus stops...");
    index = new StreetVertexIndex(graph);
    // iterate over a copy of vertex list because it will be modified
    ArrayList<Vertex> vertices = new ArrayList<>();
    vertices.addAll(graph.getVertices());
    for (TransitStopVertex ts : Iterables.filter(vertices, TransitStopVertex.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;
        // only connect transit stops that are not part of a pathway network
        if (!ts.hasPathways()) {
            boolean wheelchairAccessible = ts.hasWheelchairEntrance();
            if (!connectVertexToStop(ts, wheelchairAccessible)) {
                LOG.debug("Could not connect " + ts.getStop().getCode() + " at " + ts.getCoordinate().toString());
            // TODO OTP2 - Why is this commented out? Is it not a problem or is it to nosey?
            // LOG.warn(graph.addBuilderAnnotation(new StopUnlinked(ts)));
            }
        }
    }
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) ArrayList(java.util.ArrayList) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex)

Aggregations

StreetVertexIndex (org.opentripplanner.routing.impl.StreetVertexIndex)6 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)3 Vertex (org.opentripplanner.routing.graph.Vertex)3 Test (org.junit.Test)2 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)2 Edge (org.opentripplanner.routing.graph.Edge)2 Graph (org.opentripplanner.routing.graph.Graph)2 GraphPath (org.opentripplanner.routing.spt.GraphPath)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Point (org.locationtech.jts.geom.Point)1 FlexStopLocation (org.opentripplanner.model.FlexStopLocation)1 GenericLocation (org.opentripplanner.model.GenericLocation)1 TripPattern (org.opentripplanner.model.TripPattern)1 BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)1 State (org.opentripplanner.routing.core.State)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)1 GraphIndex (org.opentripplanner.routing.graph.GraphIndex)1 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)1