Search in sources :

Example 6 with LocationIndexedLine

use of org.locationtech.jts.linearref.LocationIndexedLine 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();
        }
        // split the edge, get the split vertex
        SplitterVertex v0 = split(edge, ll, temporaryVertex != null, endVertex);
        makeLinkEdges(tstop, v0);
        // edges that were missed by WalkableAreaBuilder
        if (edge instanceof AreaEdge && tstop instanceof TransitStopVertex && this.addExtraEdgesToAreas) {
            linkTransitToAreaVertices(v0, ((AreaEdge) edge).getArea());
        }
    }
}
Also used : LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) LocationIndexedLine(org.locationtech.jts.linearref.LocationIndexedLine) LinearLocation(org.locationtech.jts.linearref.LinearLocation) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) TemporarySplitterVertex(org.opentripplanner.routing.vertextype.TemporarySplitterVertex) TemporaryVertex(org.opentripplanner.routing.vertextype.TemporaryVertex) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge)

Example 7 with LocationIndexedLine

use of org.locationtech.jts.linearref.LocationIndexedLine in project OpenTripPlanner by opentripplanner.

the class GeometryAndBlockProcessor method getGeometriesByShape.

private LineString[] getGeometriesByShape(List<StopTime> stopTimes, FeedScopedId shapeId, LineString shape, List<LinearLocation> locations) {
    LineString[] geoms = new LineString[stopTimes.size() - 1];
    Iterator<LinearLocation> locationIt = locations.iterator();
    LinearLocation endLocation = locationIt.next();
    double distanceSoFar = 0;
    int last = 0;
    for (int i = 0; i < stopTimes.size() - 1; ++i) {
        LinearLocation startLocation = endLocation;
        endLocation = locationIt.next();
        // it does not matter at all if this is accurate so long as it is consistent
        for (int j = last; j < startLocation.getSegmentIndex(); ++j) {
            Coordinate from = shape.getCoordinateN(j);
            Coordinate to = shape.getCoordinateN(j + 1);
            double xd = from.x - to.x;
            double yd = from.y - to.y;
            distanceSoFar += FastMath.sqrt(xd * xd + yd * yd);
        }
        last = startLocation.getSegmentIndex();
        double startIndex = distanceSoFar + startLocation.getSegmentFraction() * startLocation.getSegmentLength(shape);
        // advance distanceSoFar up to start of segment containing endLocation
        for (int j = last; j < endLocation.getSegmentIndex(); ++j) {
            Coordinate from = shape.getCoordinateN(j);
            Coordinate to = shape.getCoordinateN(j + 1);
            double xd = from.x - to.x;
            double yd = from.y - to.y;
            distanceSoFar += FastMath.sqrt(xd * xd + yd * yd);
        }
        last = startLocation.getSegmentIndex();
        double endIndex = distanceSoFar + endLocation.getSegmentFraction() * endLocation.getSegmentLength(shape);
        ShapeSegmentKey key = new ShapeSegmentKey(shapeId, startIndex, endIndex);
        LineString geometry = geometriesByShapeSegmentKey.get(key);
        if (geometry == null) {
            LocationIndexedLine locationIndexed = new LocationIndexedLine(shape);
            geometry = (LineString) locationIndexed.extractLine(startLocation, endLocation);
            // Pack the resulting line string
            CoordinateSequence sequence = new PackedCoordinateSequence.Double(geometry.getCoordinates(), 2);
            geometry = geometryFactory.createLineString(sequence);
        }
        geoms[i] = geometry;
    }
    return geoms;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) LinearLocation(org.locationtech.jts.linearref.LinearLocation) LocationIndexedLine(org.locationtech.jts.linearref.LocationIndexedLine) ShapePoint(org.opentripplanner.model.ShapePoint)

Aggregations

LinearLocation (org.locationtech.jts.linearref.LinearLocation)7 LocationIndexedLine (org.locationtech.jts.linearref.LocationIndexedLine)7 Coordinate (org.locationtech.jts.geom.Coordinate)5 LineString (org.locationtech.jts.geom.LineString)5 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)2 Geometry (org.locationtech.jts.geom.Geometry)2 P2 (org.opentripplanner.common.model.P2)2 Edge (org.opentripplanner.routing.graph.Edge)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Envelope (org.locationtech.jts.geom.Envelope)1 AssertionFailedException (org.locationtech.jts.util.AssertionFailedException)1 PackedCoordinateSequence (org.opentripplanner.common.geometry.PackedCoordinateSequence)1 BinHeap (org.opentripplanner.common.pqueue.BinHeap)1 BogusShapeDistanceTraveled (org.opentripplanner.graph_builder.issues.BogusShapeDistanceTraveled)1 BogusShapeGeometry (org.opentripplanner.graph_builder.issues.BogusShapeGeometry)1 ShapePoint (org.opentripplanner.model.ShapePoint)1 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 Vertex (org.opentripplanner.routing.graph.Vertex)1