Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.CoordinateSequence


     * "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE" (no kidding!)
     */
    private LinearRing polygonClip(LinearRing ring) {
        final double INFINITY = Double.MAX_VALUE;

        CoordinateSequence cs = ring.getCoordinateSequence();
        Ordinates out = new Ordinates();

        // Coordinates of intersection between the infinite line hosting the segment and the clip area
        double xIn, xOut, yIn, yOut;
        // Parameter values of same, they are in [0,1] if the intersections are inside the segment, < 0 or > 1 otherwise
        double tInX, tOutX, tInY, tOutY;
        // tOut2: max between tOutX and tOutY, tIn2: max between tInX and tinY
        double tOut1, tOut2, tIn1, tIn2;
       
        // Direction of edge
        double deltaX, deltaY;
        int i;

        // for each edge
        for (i = 0; i < cs.size() - 1; i++) {
            // extract the edge
            double x0 = cs.getOrdinate(i, 0);
            double x1 = cs.getOrdinate(i + 1, 0);
            double y0 = cs.getOrdinate(i, 1);
            double y1 = cs.getOrdinate(i + 1, 1);
           
            // determine direction of edge
            deltaX = x1 - x0;
            deltaY = y1 - y0;

View Full Code Here


     * @param gf
     * @param csf
     * @return
     */
    LinearRing buildBoundsString(final GeometryFactory gf, final CoordinateSequenceFactory csf) {
        CoordinateSequence cs = csf.create(5, 2);
        cs.setOrdinate(0, 0, xmin);
        cs.setOrdinate(0, 1, ymin);
        cs.setOrdinate(1, 0, xmin);
        cs.setOrdinate(1, 1, ymax);
        cs.setOrdinate(2, 0, xmax);
        cs.setOrdinate(2, 1, ymax);
        cs.setOrdinate(3, 0, xmax);
        cs.setOrdinate(3, 1, ymin);
        cs.setOrdinate(4, 0, xmin);
        cs.setOrdinate(4, 1, ymin);
        return gf.createLinearRing(cs);
    }
View Full Code Here

        List<LineString> clipped = new ArrayList<LineString>();

        // grab all the factories a
        final GeometryFactory gf = line.getFactory();
        final CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory();
        final CoordinateSequence coords = line.getCoordinateSequence();

        // first step
        final Ordinates ordinates = new Ordinates(coords.size());
        double x0 = coords.getX(0);
        double y0 = coords.getY(0);
        boolean prevInside = contained(x0, y0);
        if (prevInside) {
            ordinates.add(x0, y0);
        }
        double[] segment = new double[4];
        final int size = coords.size();
        // loop over the other coordinates
        for (int i = 1; i < size; i++) {
            final double x1 = coords.getX(i);
            final double y1 = coords.getY(i);

            boolean inside = contained(x1, y1);
            if (inside == prevInside) {
                if (inside) {
                    // both segments were inside, not need for clipping
                    ordinates.add(x1, y1);
                } else {
                    // both were outside, this might still be caused by a line
                    // crossing the envelope but whose endpoints lie outside
                    if (!outside(x0, y0, x1, y1)) {
                        segment[0] = x0;
                        segment[1] = y0;
                        segment[2] = x1;
                        segment[3] = y1;
                        double[] clippedSegment = clipSegment(segment);
                        if (clippedSegment != null) {
                            CoordinateSequence cs = csf.create(2, 2);
                            cs.setOrdinate(0, 0, clippedSegment[0]);
                            cs.setOrdinate(0, 1, clippedSegment[1]);
                            cs.setOrdinate(1, 0, clippedSegment[2]);
                            cs.setOrdinate(1, 1, clippedSegment[3]);
                            clipped.add(gf.createLineString(cs));
                        }
                    }
                }
            } else {
                // one inside, the other outside, a clip must occurr
                segment[0] = x0;
                segment[1] = y0;
                segment[2] = x1;
                segment[3] = y1;
                double[] clippedSegment = clipSegment(segment);
                if (clippedSegment != null) {
                    if (prevInside) {
                        ordinates.add(clippedSegment[2], clippedSegment[3]);
                    } else {
                        ordinates.add(clippedSegment[0], clippedSegment[1]);
                        ordinates.add(clippedSegment[2], clippedSegment[3]);
                    }
                    // if we are going from inside to outside it's time to cut a linestring
                    // into the results
                    if (prevInside) {
                        // if(closed) {
                        // addClosingPoints(ordinates, shell);
                        // clipped.add(gf.createLinearRing(ordinates.toCoordinateSequence(csf)));
                        // } else {
                        clipped.add(gf.createLineString(ordinates.toCoordinateSequence(csf)));
                        // }
                        ordinates.clear();
                    }
                } else {
                    prevInside = false;
                }
            }
            prevInside = inside;
            x0 = x1;
            y0 = y1;
        }
        // don't forget the last linestring
        if (ordinates.size() > 1) {
            clipped.add(gf.createLineString(ordinates.toCoordinateSequence(csf)));
        }

        if (line.isClosed() && clipped.size() > 1) {
            // the first and last strings might be adjacent, in that case fuse them
            CoordinateSequence cs0 = clipped.get(0).getCoordinateSequence();
            CoordinateSequence cs1 = clipped.get(clipped.size() - 1).getCoordinateSequence();
            if (cs0.getOrdinate(0, 0) == cs1.getOrdinate(cs1.size() - 1, 0)
                    && cs0.getOrdinate(0, 1) == cs1.getOrdinate(cs1.size() - 1, 1)) {
                CoordinateSequence cs = csf.create(cs0.size() + cs1.size() - 1, 2);
                for (int i = 0; i < cs1.size(); i++) {
                    cs.setOrdinate(i, 0, cs1.getOrdinate(i, 0));
                    cs.setOrdinate(i, 1, cs1.getOrdinate(i, 1));
                }
                for (int i = 1; i < cs0.size(); i++) {
                    cs.setOrdinate(i + cs1.size() - 1, 0, cs0.getOrdinate(i, 0));
                    cs.setOrdinate(i + cs1.size() - 1, 1, cs0.getOrdinate(i, 1));
                }
                clipped.remove(0);
                clipped.remove(clipped.size() - 1);
                clipped.add(gf.createLineString(cs));
            }
View Full Code Here

        if (!g1.equalsExact(g2, ORD_TOLERANCE))
            return false;
        if (g1.getFactory() != g2.getFactory())
            return false;
   
        CoordinateSequence seq = CoordinateSequenceFinder.find(g1);
        if (!CoordinateSequenceSchemaChecker.check(g2, seq.getClass(),
                seq.getDimension()))
            return false;
        return true;
    }
View Full Code Here

   
    /**
     * Converts the ordinate into a coordinate sequence
     */
    public CoordinateSequence toCoordinateSequence(CoordinateSequenceFactory csfac) {
        CoordinateSequence cs = csfac.create(size(), 2);
        for (int i = 0; i <= curr; i++) {
            cs.setOrdinate(i, 0, ordinates[i * 2]);
            cs.setOrdinate(i, 1, ordinates[i * 2 + 1]);
        }
       
        return cs;
    }
View Full Code Here

    private CoordinateSequence createCS(double[] ord, int dim) {
        if (ord.length % dim != 0)
            throw new IllegalArgumentException("Ordinate array length "
                    + ord.length + " is not a multiple of dimension " + dim);
        int n = ord.length / dim;
        CoordinateSequence cs = csFact.create(n, dim);
        for (int i = 0; i < n; i++) {
            for (int d = 0; d < dim; d++)
                cs.setOrdinate(i, d, ord[dim * i + d]);
        }
        return cs;
    }
View Full Code Here

            for (int i=0; i<source.length; i++) {
                source[i] = new Coordinate(-121 4*random.nextDouble(),
                                            -45 + 90*random.nextDouble(),
                                                 500*random.nextDouble());
            }
            final CoordinateSequence sourceCS = csFactory.create(source);
            final CoordinateSequence targetCS = transform(sourceCS, t);
            assertNotSame(sourceCS, targetCS);
            assertEquals(sourceCS.size(), targetCS.size());
            for (int i=sourceCS.size(); --i>=0;) {
                assertFalse(sourceCS.getCoordinate(i).equals(targetCS.getCoordinate(i)));
            }

            final CoordinateSequenceTransformer transformer = new DefaultCoordinateSequenceTransformer();
            final CoordinateSequence testCS = transformer.transform(sourceCS, t);
            assertNotSame(sourceCS, testCS);
            assertNotSame(targetCS, testCS);
            assertEquals(sourceCS.size(), testCS.size());
            for (int i=targetCS.size(); --i>=0;) {
                assertEquals(targetCS.getCoordinate(i), testCS.getCoordinate(i));
            }
        }
    }
View Full Code Here

        CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84;
       
        DefaultCoordinateSequenceTransformer cst;
        cst = new DefaultCoordinateSequenceTransformer(/* standard cs factory */);
        MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true);
        CoordinateSequence transformed = cst.transform(cs, tx);
        CoordinateSequence reference = transform(cs, tx);
       
       
        assertEquals(reference.getOrdinate(0, 0), transformed.getOrdinate(0, 0), 0.0);
        assertEquals(reference.getOrdinate(0, 1), transformed.getOrdinate(0, 1), 0.0);
        assertEquals(Double.NaN, transformed.getOrdinate(0, 2), 0.0);
    }
View Full Code Here

        // check the first polygon
        SimpleFeature f = fi.next();
        MultiLineString ml = (MultiLineString) f.getDefaultGeometry();
        assertEquals(1, ml.getNumGeometries());
        LineString ls = (LineString) ml.getGeometryN(0);
        CoordinateSequence cs = ls.getCoordinateSequence();
        assertEquals(3, cs.size());
        assertOrdinates(0, 0, 0, cs, 0);
        assertOrdinates(10000, 0, 1, cs, 1);
        assertOrdinates(10000, 10000, 2, cs, 2);
        fi.close();
    }
View Full Code Here

        // check the first polygon
        SimpleFeature f = fi.next();
        MultiLineString ml = (MultiLineString) f.getDefaultGeometry();
        assertEquals(1, ml.getNumGeometries());
        LineString ls = (LineString) ml.getGeometryN(0);
        CoordinateSequence cs = ls.getCoordinateSequence();
        assertEquals(2, cs.size());
        assertOrdinates(0, 0, 0, cs, 0);
        assertOrdinates(5000, 0, 0.5, cs, 1);
        fi.close();
    }
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.