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);
}
}
}
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());
}
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());
}
}
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();
}
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)));
}
}
}
}
Aggregations