Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.CoordinateSequence


    /* PRIVATE METHODS */

    /** Initializes this.nearestPointOnEdge and other distance-related variables. */
    private double calcNearestPoint(Coordinate p) {
        LineString edgeGeom = edge.getGeometry();
        CoordinateSequence coordSeq = edgeGeom.getCoordinateSequence();
        int bestSeg = 0;
        double bestDist2 = Double.POSITIVE_INFINITY;
        double bestFrac = 0;
        double xscale = Math.cos(p.y * Math.PI / 180);
        for (int seg = 0; seg < numEdgeCoords - 1; seg++) {
            double x0 = coordSeq.getX(seg);
            double y0 = coordSeq.getY(seg);
            double x1 = coordSeq.getX(seg + 1);
            double y1 = coordSeq.getY(seg + 1);
            double frac = GeometryUtils.segmentFraction(x0, y0, x1, y1, p.x, p.y, xscale);
            // project to get closest point
            double x = x0 + frac * (x1 - x0);
            double y = y0 + frac * (y1 - y0);
            // find ersatz distance to edge (do not take root)
View Full Code Here


            /* LineString.getCoordinates() uses PackedCoordinateSequence.toCoordinateArray() which
             * necessarily builds new Coordinate objects.CoordinateSequence.getOrdinate() reads them
             * directly. */
            c.edge = edge;
            LineString ls = (LineString)(edge.getGeometry());
            CoordinateSequence coordSeq = ls.getCoordinateSequence();
            int numCoords = coordSeq.size();
            for (int seg = 0; seg < numCoords - 1; seg++) {
                c.seg = seg;
                double x0 = coordSeq.getX(seg);
                double y0 = coordSeq.getY(seg);
                double x1 = coordSeq.getX(seg+1);
                double y1 = coordSeq.getY(seg+1);
                // use bounding rectangle to find a lower bound on (squared) distance ?
                // this would mean more squaring or roots.
                c.frac = GeometryUtils.segmentFraction(x0, y0, x1, y1, pt.x, pt.y, xscale);
                // project to get closest point
                c.x = x0 + c.frac * (x1 - x0);
View Full Code Here

        public double distanceTo(Coordinate c) {
            return distanceLibrary.fastDistance(y, x, c.y, c.x);
        }
       
        public double distanceAlong() {
            CoordinateSequence cs = ( (LineString)(edge.getGeometry()) ).getCoordinateSequence();
            double dist = 0;
            double x0 = cs.getX(0);
            double y0 = cs.getY(0);
            for (int s = 1; s < seg; s++) {
                double x1 = cs.getX(s);
                double y1 = cs.getY(s);
                dist += distanceLibrary.fastDistance(y0, x0, y1, x1);
                x0 = x1;
                y0 = y1;
            }
            dist += distanceLibrary.fastDistance(y0, x0, y, x); // dist along partial segment
View Full Code Here

            dist += distanceLibrary.fastDistance(y0, x0, y, x); // dist along partial segment
            return dist;
        }

        public double distanceToEnd() {
            CoordinateSequence cs = ( (LineString)(edge.getGeometry()) ).getCoordinateSequence();
            int s = seg + 1;
            double x0 = cs.getX(s);
            double y0 = cs.getY(s);
            double dist = distanceLibrary.fastDistance(y0, x0, y, x); // dist along partial segment
            int nc = cs.size();
            for (; s < nc; s++) {
                double x1 = cs.getX(s);
                double y1 = cs.getY(s);
                dist += distanceLibrary.fastDistance(y0, x0, y1, x1);
                x0 = x1;
                y0 = y1;
            }
            return dist;
View Full Code Here

        runOneTest(new Coordinate[] { new Coordinate(0.0, 0.12345678), new Coordinate(1.1111111111, -0.987654321),
                new Coordinate(2.222222222222, 0.0000123), new Coordinate(3.33333333333, 6789.987654321) });
    }

    private void runOneTest(Coordinate[] c) {
        CoordinateSequence elev1 = c == null ? null : new PackedCoordinateSequence.Double(c);
        byte[] packed = CompactElevationProfile.compactElevationProfile(elev1);
        CoordinateSequence elev2 = CompactElevationProfile.uncompactElevationProfile(packed);
        if (elev1 == null) {
            // This is rather simple
            assertNull(elev2);
            return;
        }
        assertEquals(elev1.size(), elev2.size());
        for (int i = 0; i < elev1.size(); i++) {
            Coordinate c1 = elev1.getCoordinate(i);
            Coordinate c2 = elev2.getCoordinate(i);
            double dx = Math.abs(c1.x - c2.x);
            double dy = Math.abs(c1.y - c2.y);
            assertTrue("Too large arc length delta", dx <= 1e-2);
            assertTrue("Too large elevation delta", dy <= 1e-2);
        }
View Full Code Here

        referenceCoordinates[8][0] = coordinates;

        GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
        CoordinateSequenceFactory coordinateSequenceFactory =
                geometryFactory.getCoordinateSequenceFactory();
        CoordinateSequence sequence = coordinateSequenceFactory.create(coordinates);
        LineString geometry = new LineString(sequence, geometryFactory);

        P2<LineString> result;
        LineString[][] results = new LineString[9][2];
View Full Code Here

public class TestElevationUtils extends TestCase {

  public void testLengthMultiplier() {

    PackedCoordinateSequenceFactory factory = PackedCoordinateSequenceFactory.DOUBLE_FACTORY;
    CoordinateSequence seq = factory.create(new Coordinate[] {
        new Coordinate(0, 1), new Coordinate(10, 1) });
    SlopeCosts costs = ElevationUtils.getSlopeCosts(seq, false);
    assertEquals(1.0, costs.lengthMultiplier);
   
    seq = factory.create(new Coordinate[] {
View Full Code Here

        when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));

        GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
        CoordinateSequenceFactory coordinateSequenceFactory =
                geometryFactory.getCoordinateSequenceFactory();
        CoordinateSequence coordinateSequence = coordinateSequenceFactory.create(coordinates);
        LineString geometry = new LineString(coordinateSequence, geometryFactory);
        ArrayList<Edge> hops = new ArrayList<Edge>(2);
        RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
        AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
        Route route = new Route();
View Full Code Here

     * Splits the input geometry into two LineStrings at a fraction of the distance covered.
     */
    public static P2<LineString> splitGeometryAtFraction(Geometry geometry, double fraction) {
        LineString empty = new LineString(null, gf);
        Coordinate[] coordinates = geometry.getCoordinates();
        CoordinateSequence sequence = gf.getCoordinateSequenceFactory().create(coordinates);
        LineString total = new LineString(sequence, gf);

        if (coordinates.length < 2) return new P2<LineString>(empty, empty);
        if (fraction <= 0) return new P2<LineString>(empty, total);
        if (fraction >= 1) return new P2<LineString>(total, empty);
View Full Code Here

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

TOP

Related Classes of com.vividsolutions.jts.geom.CoordinateSequence

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.