Search in sources :

Example 6 with LocationIndexedLine

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

the class GTFSPatternHopFactory method getHopGeometryViaShapeDistTraveled.

private LineString getHopGeometryViaShapeDistTraveled(Graph graph, AgencyAndId shapeId, StopTime st0, StopTime st1) {
    double startDistance = st0.getShapeDistTraveled();
    double endDistance = st1.getShapeDistTraveled();
    ShapeSegmentKey key = new ShapeSegmentKey(shapeId, startDistance, endDistance);
    LineString geometry = _geometriesByShapeSegmentKey.get(key);
    if (geometry != null)
        return geometry;
    double[] distances = getDistanceForShapeId(shapeId);
    if (distances == null) {
        LOG.warn(graph.addBuilderAnnotation(new BogusShapeGeometry(shapeId)));
        return null;
    } else {
        LinearLocation startIndex = getSegmentFraction(distances, startDistance);
        LinearLocation endIndex = getSegmentFraction(distances, endDistance);
        if (equals(startIndex, endIndex)) {
            // bogus shape_dist_traveled
            graph.addBuilderAnnotation(new BogusShapeDistanceTraveled(st1));
            return createSimpleGeometry(st0.getStop(), st1.getStop());
        }
        LineString line = getLineStringForShapeId(shapeId);
        LocationIndexedLine lol = new LocationIndexedLine(line);
        geometry = getSegmentGeometry(graph, shapeId, lol, startIndex, endIndex, startDistance, endDistance, st0, st1);
        return geometry;
    }
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) BogusShapeGeometry(org.opentripplanner.graph_builder.annotation.BogusShapeGeometry) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) LocationIndexedLine(com.vividsolutions.jts.linearref.LocationIndexedLine) BogusShapeDistanceTraveled(org.opentripplanner.graph_builder.annotation.BogusShapeDistanceTraveled)

Example 7 with LocationIndexedLine

use of com.vividsolutions.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();
        }
        // 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)

Aggregations

LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)7 LocationIndexedLine (com.vividsolutions.jts.linearref.LocationIndexedLine)7 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 ArrayList (java.util.ArrayList)2 P2 (org.opentripplanner.common.model.P2)2 Edge (org.opentripplanner.routing.graph.Edge)2 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 AssertionFailedException (com.vividsolutions.jts.util.AssertionFailedException)1 TIntList (gnu.trove.list.TIntList)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)1 Stop (org.onebusaway.gtfs.model.Stop)1 StopTime (org.onebusaway.gtfs.model.StopTime)1