use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.
the class LocationStringParserTest method testWithId.
@Test
public void testWithId() {
GenericLocation loc = LocationStringParser.fromOldStyleString("name::aFeed:A1B2C3");
assertEquals("name", loc.label);
assertEquals(loc.stopId, new FeedScopedId("aFeed", "A1B2C3"));
assertNull(loc.lat);
assertNull(loc.lng);
assertNull(loc.getCoordinate());
loc = LocationStringParser.fromOldStyleString("feed:4321");
assertNull(loc.label);
assertEquals(loc.stopId, new FeedScopedId("feed", "4321"));
assertNull(loc.lat);
assertNull(loc.lng);
assertNull(loc.getCoordinate());
}
use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testStreetLocationFinder.
@Test
public void testStreetLocationFinder() {
RoutingRequest options = new RoutingRequest();
StreetVertexIndex finder = graph.getStreetIndex();
Set<DisposableEdgeCollection> tempEdges = new HashSet<>();
// 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.getVertexForLocationForTest(new GenericLocation(40.00, -74.00), options, true, tempEdges);
assertNotNull(some);
// test that the closest vertex finder correctly splits streets
TemporaryStreetLocation start = (TemporaryStreetLocation) finder.getVertexForLocationForTest(new GenericLocation(40.004, -74.01), options, false, tempEdges);
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.getVertexForLocationForTest(new GenericLocation(40.008, -74.0), biking, true, tempEdges);
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.getVertexForLocationForTest(new GenericLocation(40.004, -74.0), walking, false, tempEdges);
end = (TemporaryStreetLocation) finder.getVertexForLocationForTest(new GenericLocation(40.008, -74.0), walking, true, tempEdges);
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();
tempEdges.forEach(DisposableEdgeCollection::disposeEdges);
}
use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.
the class SplitEdgeTurnRestrictionsTest method computeCarPolyline.
private static String computeCarPolyline(Graph graph, GenericLocation from, GenericLocation to) {
RoutingRequest request = new RoutingRequest();
request.setDateTime(dateTime);
request.from = from;
request.to = to;
request.streetSubRequestModes = new TraverseModeSet(TraverseMode.CAR);
request.setRoutingContext(graph);
var gpf = new GraphPathFinder(new Router(graph, RouterConfig.DEFAULT));
var paths = gpf.graphPathFinderEntryPoint(request);
var itineraries = GraphPathToItineraryMapper.mapItineraries(paths);
// make sure that we only get CAR legs
itineraries.forEach(i -> i.legs.forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.CAR)));
Geometry geometry = itineraries.get(0).legs.get(0).getLegGeometry();
return PolylineEncoder.createEncodings(geometry).getPoints();
}
use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.
the class StreetGraphFinder method findClosestUsingStreets.
private void findClosestUsingStreets(double lat, double lon, double radius, TraverseVisitor visitor, SearchTerminationStrategy terminationStrategy) {
// Make a normal OTP routing request so we can traverse edges and use GenericAStar
// TODO make a function that builds normal routing requests from profile requests
RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
rr.from = new GenericLocation(null, null, lat, lon);
rr.oneToMany = true;
rr.setRoutingContext(graph);
rr.walkSpeed = 1;
rr.dominanceFunction = new DominanceFunction.LeastWalk();
rr.rctx.remainingWeightHeuristic = new TrivialRemainingWeightHeuristic();
// RR dateTime defaults to currentTime.
// If elapsed time is not capped, searches are very slow.
rr.worstTime = (rr.dateTime + (int) radius);
AStar astar = new AStar();
rr.setNumItineraries(1);
astar.setTraverseVisitor(visitor);
// timeout in seconds
astar.getShortestPathTree(rr, 1, terminationStrategy);
// Destroy the routing context, to clean up the temporary edges & vertices
rr.rctx.destroy();
}
use of org.opentripplanner.model.GenericLocation in project OpenTripPlanner by opentripplanner.
the class BicycleRoutingTest method computePolyline.
private static String computePolyline(Graph graph, GenericLocation from, GenericLocation to) {
RoutingRequest request = new RoutingRequest();
request.setDateTime(dateTime);
request.from = from;
request.to = to;
request.bicycleOptimizeType = BicycleOptimizeType.QUICK;
request.streetSubRequestModes = new TraverseModeSet(TraverseMode.BICYCLE);
request.setRoutingContext(graph);
var gpf = new GraphPathFinder(new Router(graph, RouterConfig.DEFAULT));
var paths = gpf.graphPathFinderEntryPoint(request);
var itineraries = GraphPathToItineraryMapper.mapItineraries(paths);
// make sure that we only get BICYLE legs
itineraries.forEach(i -> i.legs.forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.BICYCLE)));
Geometry legGeometry = itineraries.get(0).legs.get(0).getLegGeometry();
return PolylineEncoder.createEncodings(legGeometry).getPoints();
}
Aggregations