Package com.vividsolutions.jts.linearref

Examples of com.vividsolutions.jts.linearref.LocationIndexedLine


              }
             
              Coordinate[] coordArray = coords.toArray(new Coordinate[coords.size()]);
             
              LineString ls = (LineString) JTS.transform(geometryFactory.createLineString(coordArray), mt);
              LocationIndexedLine indexLine = new LocationIndexedLine(ls);
             
              Logger.info("length: " + ls.getLength());
             
              patternStops = TripPatternStop.find("pattern = ?", tripPattern).fetch();
             
              for(TripPatternStop patternStop : patternStops) {
               
               
                Point p = (Point) JTS.transform(patternStop.stop.locationPoint(), mt);
               
                LinearLocation l = indexLine.project(p.getCoordinate());
                patternStop.defaultDistance = LengthLocationMap.getLength(ls, l);
                patternStop.save();
              }
            }
           
View Full Code Here


    /**
     * Splits the input geometry into two LineStrings at the given point.
     */
    public static P2<LineString> splitGeometryAtPoint(Geometry geometry, Coordinate nearestPoint) {
        // An index in JTS can actually refer to any point along the line. It is NOT an array index.
        LocationIndexedLine line = new LocationIndexedLine(geometry);
        LinearLocation l = line.indexOf(nearestPoint);

        LineString beginning = (LineString) line.extractLine(line.getStartIndex(), l);
        LineString ending = (LineString) line.extractLine(l, line.getEndIndex());

        return new P2<LineString>(beginning, ending);
    }
View Full Code Here

        double totalDistance = total.getLength();
        double requestedDistance = totalDistance * fraction;

        // An index in JTS can actually refer to any point along the line. It is NOT an array index.
        LocationIndexedLine line = new LocationIndexedLine(geometry);
        LinearLocation l = LengthLocationMap.getLocation(geometry, requestedDistance);

        LineString beginning = (LineString) line.extractLine(line.getStartIndex(), l);
        LineString ending = (LineString) line.extractLine(l, line.getEndIndex());

        return new P2<LineString>(beginning, ending);
    }
View Full Code Here

            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);
View Full Code Here

                //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;
View Full Code Here

        this.routeGeometry = routeGeometry;
        this.routeIndex = routeIndex;
        this.edgeIndex = edgeIndex;

        edgeGeometry = edge.getGeometry();
        indexedEdge = new LocationIndexedLine(edgeGeometry);
        currentError = error;
    }
View Full Code Here

                // along this route segment

                // find nearest point that makes progress along the route
                Vertex toVertex = edge.getToVertex();
                Coordinate endCoord = toVertex.getCoordinate();
                LocationIndexedLine indexedRoute = new LocationIndexedLine(routeGeometry);

                // FIXME: it would be better to do this project/indexOfAfter in one step
                // as the two-step version could snap to a bad place and be unable to escape.

                LinearLocation routeProjectedEndIndex = indexedRoute.project(endCoord);
                Coordinate routeProjectedEndCoord = routeProjectedEndIndex
                        .getCoordinate(routeGeometry);

                if (routeProjectedEndIndex.compareTo(routeIndex) <= 0) {
                    try {
                        routeProjectedEndIndex = indexedRoute.indexOfAfter(routeProjectedEndCoord,
                                routeIndex);
                        if (Double.isNaN(routeProjectedEndIndex.getSegmentFraction())) {
                            // can't go forward
                            routeProjectedEndIndex = routeIndex; // this is bad, but not terrible
                                                                 // since we are advancing along the edge
                        }
                    } catch (AssertionFailedException e) {
                        routeProjectedEndIndex = routeIndex;
                    }
                    routeProjectedEndCoord = routeProjectedEndIndex.getCoordinate(routeGeometry);
                }

                double positionError = distance(routeProjectedEndCoord, endCoord);
                double travelAlongRoute = distanceAlongGeometry(routeGeometry, routeIndex,
                        routeProjectedEndIndex);
                double travelAlongEdge = distanceAlongGeometry(edgeGeometry, edgeIndex,
                        newEdgeIndex);
                double travelError = Math.abs(travelAlongEdge - travelAlongRoute);

                double error = positionError + travelError;
               
                if (error > MAX_ERROR) {
                    // we're not going to bother with states which are
                    // totally wrong
                    return nextStates;
                }
               
                for (Edge e : getOutgoingMatchableEdges(toVertex)) {
                    double cost = error + NEW_SEGMENT_PENALTY;
                    if (!carsCanTraverse(e)) {
                        cost += NO_TRAVERSE_PENALTY;
                    }
                    MatchState nextState = new MidblockMatchState(this, routeGeometry, e,
                            routeProjectedEndIndex, new LinearLocation(), cost, travelAlongRoute);
                    nextStates.add(nextState);
                }

            } else {

                double travelAlongEdge = distanceAlongGeometry(edgeGeometry, edgeIndex,
                        newEdgeIndex);
                double travelAlongRoute = distanceAlongGeometry(routeGeometry, routeIndex,
                        routeSuccessor);
                double travelError = Math.abs(travelAlongRoute - travelAlongEdge);

                double positionError = distance(edgeCoord, newRouteCoord);

                double error = travelError + positionError;

                MatchState nextState = new MidblockMatchState(this, routeGeometry, edge,
                        routeSuccessor, newEdgeIndex, error, travelAlongRoute);
                nextStates.add(nextState);

                // it's also possible that, although we have not yet reached the end of this edge,
                // we are going to turn, because the route turns earlier than the edge. In that
                // case, we jump to the corner, and our error is the distance from the route point
                // and the corner

                Vertex toVertex = edge.getToVertex();
                double travelAlongOldEdge = distanceAlongGeometry(edgeGeometry, edgeIndex, null);

                for (Edge e : getOutgoingMatchableEdges(toVertex)) {
                    Geometry newEdgeGeometry = e.getGeometry();
                    LocationIndexedLine newIndexedEdge = new LocationIndexedLine(newEdgeGeometry);
                    newEdgeIndex = newIndexedEdge.project(newRouteCoord);
                    Coordinate newEdgeCoord = newEdgeIndex.getCoordinate(newEdgeGeometry);
                    positionError = distance(newEdgeCoord, newRouteCoord);
                    travelAlongEdge = travelAlongOldEdge + distanceAlongGeometry(newEdgeGeometry, new LinearLocation(), newEdgeIndex);
                    travelError = Math.abs(travelAlongRoute - travelAlongEdge);
View Full Code Here

            return null;
       
        routeGeometry = DouglasPeuckerSimplifier.simplify(routeGeometry, 0.00001);

        // initial state: start midway along a block.
        LocationIndexedLine indexedLine = new LocationIndexedLine(routeGeometry);

        LinearLocation startIndex = indexedLine.getStartIndex();

        Coordinate routeStartCoordinate = startIndex.getCoordinate(routeGeometry);
        Envelope envelope = new Envelope(routeStartCoordinate);
        double distanceThreshold = DISTANCE_THRESHOLD;
        envelope.expandBy(distanceThreshold);

        BinHeap<MatchState> states = new BinHeap<MatchState>();
        List<Edge> nearbyEdges = index.query(envelope);
        while (nearbyEdges.isEmpty()) {
            envelope.expandBy(distanceThreshold);
            distanceThreshold *= 2;
            nearbyEdges = index.query(envelope);
        }

        // compute initial states
        for (Edge initialEdge : nearbyEdges) {
            Geometry edgeGeometry = initialEdge.getGeometry();
           
            LocationIndexedLine indexedEdge = new LocationIndexedLine(edgeGeometry);
            LinearLocation initialLocation = indexedEdge.project(routeStartCoordinate);
           
            double error = MatchState.distance(initialLocation.getCoordinate(edgeGeometry), routeStartCoordinate);
            MidblockMatchState state = new MidblockMatchState(null, routeGeometry, initialEdge, startIndex, initialLocation, error, 0.01);
            states.insert(state, 0); //make sure all initial states are visited by inserting them at 0
        }
View Full Code Here

                for (Vertex v : vertices) {
                    Coordinate c;
                    if (v instanceof StreetVertex) {
                        LineString ls = ((StreetVertex)v).getOutgoing().iterator().next().getGeometry();
                        int numPoints = ls.getNumPoints();
                        LocationIndexedLine lil = new LocationIndexedLine(ls);
                        int seg = random.nextInt(numPoints);
                        double frac = random.nextDouble();
                        LinearLocation ll = new LinearLocation(seg, frac);
                        c = lil.extractPoint(ll);
                    } else {
                        c = v.getCoordinate();
                    }
                    // perturb
                    double distance = random.nextDouble() * radius;
 
View Full Code Here

        Point point = pointExpression.evaluate(object, Point.class);
   
        Expression lineExpression = parameters.get(1);
        Geometry line = lineExpression.evaluate(object, Geometry.class);
   
        LocationIndexedLine index = new LocationIndexedLine(line);
   
        LinearLocation location = index.project(point.getCoordinate());
   
        Coordinate snap = index.extractPoint(location);
   
        Point pt = point.getFactory().createPoint(snap);
   
        return Converters.convert(pt, context); // convert to requested format
    }
View Full Code Here

TOP

Related Classes of com.vividsolutions.jts.linearref.LocationIndexedLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.