Search in sources :

Example 11 with LinearLocation

use of com.vividsolutions.jts.linearref.LinearLocation in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitter method link.

/**
 * split the edge and link in the transit stop
 */
private void link(Vertex tstop, StreetEdge edge, double xscale, RoutingRequest options) {
    // TODO: we've already built this line string, we should save it
    LineString orig = edge.getGeometry();
    LineString transformed = equirectangularProject(orig, xscale);
    LocationIndexedLine il = new LocationIndexedLine(transformed);
    LinearLocation ll = il.project(new Coordinate(tstop.getLon() * xscale, tstop.getLat()));
    // street to use the same vertices. Otherwise the order the stops are loaded in will affect where they are snapped.
    if (ll.getSegmentIndex() == 0 && ll.getSegmentFraction() < 1e-8) {
        makeLinkEdges(tstop, (StreetVertex) edge.getFromVertex());
    } else // past the last point
    if (ll.getSegmentIndex() == orig.getNumPoints() - 1) {
        makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
    } else // nPoints - 2: -1 to correct for index vs count, -1 to account for fencepost problem
    if (ll.getSegmentIndex() == orig.getNumPoints() - 2 && ll.getSegmentFraction() > 1 - 1e-8) {
        makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
    } else {
        TemporaryVertex temporaryVertex = null;
        boolean endVertex = false;
        if (tstop instanceof TemporaryVertex) {
            temporaryVertex = (TemporaryVertex) tstop;
            endVertex = temporaryVertex.isEndVertex();
        }
        // It is only used in origin/destination linking since otherwise options is null
        if (options != null) {
            options.canSplitEdge(edge);
        }
        // split the edge, get the split vertex
        SplitterVertex v0 = split(edge, ll, temporaryVertex != null, endVertex);
        makeLinkEdges(tstop, v0);
    }
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) LocationIndexedLine(com.vividsolutions.jts.linearref.LocationIndexedLine) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TemporarySplitterVertex(org.opentripplanner.routing.vertextype.TemporarySplitterVertex) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) TemporaryVertex(org.opentripplanner.routing.vertextype.TemporaryVertex)

Example 12 with LinearLocation

use of com.vividsolutions.jts.linearref.LinearLocation in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testRouteToSameEdge.

@Test
public void testRouteToSameEdge() {
    RoutingRequest options = new RoutingRequest();
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), true);
    assertEquals(start.getX(), end.getX(), 0.0001);
    assertTrue(start.getY() < end.getY());
    Collection<Edge> edges = end.getIncoming();
    assertEquals(2, edges.size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
    options.dateTime = startTime;
    options.setRoutingContext(graph, start, end);
    options.setMaxWalkDistance(Double.MAX_VALUE);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(end, false);
    assertNotNull("There must be a path from start to end", path);
    assertEquals(1, path.edges.size());
    options.cleanup();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with LinearLocation

use of com.vividsolutions.jts.linearref.LinearLocation in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testStreetSplittingAlerts.

/**
 * Test that alerts on split streets are preserved, i.e. if there are alerts on the street that is split the same alerts should be present on the
 * new street.
 */
@Test
public void testStreetSplittingAlerts() {
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    Alert alert = Alert.createSimpleAlerts("This is the alert");
    Set<Alert> alerts = new HashSet<>();
    alerts.add(alert);
    graph.streetNotesService.addStaticNote(left, alert, StreetNotesService.ALWAYS_MATCHER);
    graph.streetNotesService.addStaticNote(leftBack, alert, StreetNotesService.ALWAYS_MATCHER);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    // The alert should be preserved
    // traverse the FreeEdge from the StreetLocation to the new IntersectionVertex
    RoutingRequest req = new RoutingRequest();
    req.setMaxWalkDistance(Double.MAX_VALUE);
    State traversedOne = new State(start, req);
    State currentState;
    for (Edge e : start.getOutgoing()) {
        currentState = e.traverse(traversedOne);
        if (currentState != null) {
            traversedOne = currentState;
            break;
        }
    }
    assertEquals(alerts, graph.streetNotesService.getNotes(traversedOne));
    assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
    assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
    // now, make sure wheelchair alerts are preserved
    Alert wheelchairAlert = Alert.createSimpleAlerts("This is the wheelchair alert");
    Set<Alert> wheelchairAlerts = new HashSet<>();
    wheelchairAlerts.add(wheelchairAlert);
    graph.streetNotesService.removeStaticNotes(left);
    graph.streetNotesService.removeStaticNotes(leftBack);
    graph.streetNotesService.addStaticNote(left, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
    graph.streetNotesService.addStaticNote(leftBack, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
    req.setWheelchairAccessible(true);
    start.dispose();
    start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    traversedOne = new State(start, req);
    for (Edge e : start.getOutgoing()) {
        currentState = e.traverse(traversedOne);
        if (currentState != null) {
            traversedOne = currentState;
            break;
        }
    }
    assertEquals(wheelchairAlerts, graph.streetNotesService.getNotes(traversedOne));
    assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
    assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
    start.dispose();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) Alert(org.opentripplanner.routing.alertpatch.Alert) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with LinearLocation

use of com.vividsolutions.jts.linearref.LinearLocation in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testRouteToSameEdgeBackwards.

@Test
public void testRouteToSameEdgeBackwards() {
    RoutingRequest options = new RoutingRequest();
    // Sits only on the leftmost edge, not on its reverse.
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), false);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), true);
    assertEquals(start.getX(), end.getX(), 0.001);
    assertTrue(start.getY() > end.getY());
    Collection<Edge> edges = end.getIncoming();
    assertEquals(1, edges.size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
    options.dateTime = startTime;
    options.setRoutingContext(graph, start, end);
    options.setMaxWalkDistance(Double.MAX_VALUE);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(end, false);
    assertNotNull("There must be a path from start to end", path);
    assertTrue(path.edges.size() > 1);
    options.cleanup();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)14 LocationIndexedLine (com.vividsolutions.jts.linearref.LocationIndexedLine)7 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 Edge (org.opentripplanner.routing.graph.Edge)6 HashSet (java.util.HashSet)5 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)5 Test (org.junit.Test)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)4 TemporaryFreeEdge (org.opentripplanner.routing.edgetype.TemporaryFreeEdge)4 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)4 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)4 LineString (com.vividsolutions.jts.geom.LineString)3 GraphPath (org.opentripplanner.routing.spt.GraphPath)3 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)2 Stop (org.onebusaway.gtfs.model.Stop)2 StopTime (org.onebusaway.gtfs.model.StopTime)2