Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.CoordinateSequence


        }
       
        public Object getSimplifiedShape() {
            CoordinateSequenceFactory csf = geometryFactory.getCoordinateSequenceFactory();
            if(type.isPointType()) {
                CoordinateSequence cs = csf.create(1, 2);
                cs.setOrdinate(0, 0, (minX + maxX) / 2);
                cs.setOrdinate(0, 1, (minY + maxY) / 2);
                return geometryFactory.createMultiPoint(new Point[] {geometryFactory.createPoint(cs)});
            } else if(type.isLineType()) {
                CoordinateSequence cs = csf.create(2, 2);
                cs.setOrdinate(0, 0, minX);
                cs.setOrdinate(0, 1, minY);
                cs.setOrdinate(1, 0, maxX);
                cs.setOrdinate(1, 1, maxY);
                return geometryFactory.createMultiLineString(new LineString[] {geometryFactory.createLineString(cs)});
            } else if(type.isPolygonType()) {
                CoordinateSequence cs = csf.create(5, 2);
                cs.setOrdinate(0, 0, minX);
                cs.setOrdinate(0, 1, minY);
                cs.setOrdinate(1, 0, minX);
                cs.setOrdinate(1, 1, maxY);
                cs.setOrdinate(2, 0, maxX);
                cs.setOrdinate(2, 1, maxY);
                cs.setOrdinate(3, 0, maxX);
                cs.setOrdinate(3, 1, minY);
                cs.setOrdinate(4, 0, minX);
                cs.setOrdinate(4, 1, minY);
                LinearRing ring = geometryFactory.createLinearRing(cs);
                return geometryFactory.createMultiPolygon(new Polygon[] {geometryFactory.createPolygon(ring, null)});
            } else {
                return shape();
            }
View Full Code Here


    public void filter(Geometry geom) {
        // this filter will receive either points, which we don't consider,
        // or lines, that we need to wrap
        if (geom instanceof LineString) {
            LineString ls = (LineString) geom;
            CoordinateSequence cs = ls.getCoordinateSequence();
            int direction = getDisconinuityDirection(cs);
            if (direction == NOWRAP)
                return;
           
            boolean ring = geom instanceof LinearRing || cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1));
            applyOffset(cs, direction == EAST_TO_WEST ? 0 : wrapLimit * 2, ring);
        }
    }
View Full Code Here

        // read bounding box (not needed)
        buffer.position(buffer.position() + 4 * 8);

        int numpoints = buffer.getInt();
        int dimensions = shapeType == shapeType.MULTIPOINTZ && !flatGeometry ? 3 : 2;
        CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(numpoints, dimensions);

        DoubleBuffer dbuffer = buffer.asDoubleBuffer();
        double[] ordinates = new double[numpoints * 2];
        dbuffer.get(ordinates);
        for (int t = 0; t < numpoints; t++) {
            cs.setOrdinate(t, 0, ordinates[t * 2]);
            cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
        }

        if (dimensions > 2) {
            dbuffer.position(dbuffer.position() + 2);

            dbuffer.get(ordinates, 0, numpoints);
            for (int t = 0; t < numpoints; t++) {
                cs.setOrdinate(t, 2, ordinates[t]); // z
            }
        }

        return geometryFactory.createMultiPoint(cs);
    }
View Full Code Here

                clonePoint = true;
            } else {
                clonePoint = false;
            }

            CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(length, dimensions);
            double[] xy = new double[xyLength * 2];
            doubleBuffer.get(xy);
            for (int i = 0; i < xyLength; i++) {
                cs.setOrdinate(i, 0, xy[i * 2]);
                cs.setOrdinate(i, 1, xy[i * 2 + 1]);
            }

            if (clonePoint) {
                cs.setOrdinate(1, 0, cs.getOrdinate(0, 0));
                cs.setOrdinate(1, 1, cs.getOrdinate(0, 1));
            }

            lines[part] = cs;
        }

View Full Code Here

                idx = idx + lines[i].size();
            }
        }
       
        for(int lineN = 0; lineN < lines.length; lineN++){
            CoordinateSequence coords = lines[lineN];
            if (shapeType == ShapeType.ARCZ) {
                JTSUtilities.zMinMax(coords, zExtreame);
            }
            final int ncoords = coords.size();
           
            for (int t = 0; t < ncoords; t++) {
                buffer.putDouble(coords.getX(t));
                buffer.putDouble(coords.getY(t));
            }
        }

        if (shapeType == ShapeType.ARCZ) {
            if (Double.isNaN(zExtreame[0])) {
                buffer.putDouble(0.0);
                buffer.putDouble(0.0);
            } else {
                buffer.putDouble(zExtreame[0]);
                buffer.putDouble(zExtreame[1]);
            }

            for(int lineN = 0; lineN < lines.length; lineN++){
                final CoordinateSequence coords = lines[lineN];
                final int ncoords = coords.size();
                double z;
                for (int t = 0; t < ncoords; t++) {
                    z = coords.getOrdinate(t, 2);   
                    if (Double.isNaN(z)) {
                        buffer.putDouble(0.0);
                    } else {
                        buffer.putDouble(z);
                    }
View Full Code Here

     */
    public static final LinearRing reverseRing(LinearRing lr) {
    GeometryFactory gf = lr.getFactory();
    CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory();

    CoordinateSequence csOrig = lr.getCoordinateSequence();
    int numPoints = csOrig.size();
    int dimensions = csOrig.getDimension();
    CoordinateSequence csNew = csf.create(numPoints, dimensions);

    for (int i = 0; i < numPoints; i++) {
      for (int j = 0; j < dimensions; j++) {
        csNew.setOrdinate(numPoints-1-i, j, csOrig.getOrdinate(i, j));
      }
    }
   
    return gf.createLinearRing(csNew);
    }
View Full Code Here

        if (type == ShapeType.NULL) {
            return createNull();
        }
       
        int dimension = shapeType == ShapeType.POINTZ && !flatGeometry ? 3 : 2;
        CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(1, dimension);
        cs.setOrdinate(0, 0, buffer.getDouble());
        cs.setOrdinate(0, 1, buffer.getDouble());

        if (shapeType == ShapeType.POINTM) {
            buffer.getDouble();
        }
       
        if (dimension > 2) {
            cs.setOrdinate(0, 2, buffer.getDouble());
        }

        return geometryFactory.createPoint(cs);
    }
View Full Code Here

            partOffsets[i] = buffer.getInt();
        }

        ArrayList shells = new ArrayList();
        ArrayList holes = new ArrayList();
        CoordinateSequence coords = readCoordinates(buffer, numPoints, dimensions);

        int offset = 0;
        int start;
        int finish;
        int length;

        for (int part = 0; part < numParts; part++) {
            start = partOffsets[part];

            if (part == (numParts - 1)) {
                finish = numPoints;
            } else {
                finish = partOffsets[part + 1];
            }

            length = finish - start;
            int close = 0; // '1' if the ring must be closed, '0' otherwise
            if ((coords.getOrdinate(start, 0) != coords.getOrdinate(finish - 1, 0))
                    || (coords.getOrdinate(start, 1) != coords.getOrdinate(finish - 1, 1))
            ) {
                close=1;
            }
            if (dimensions == 3) {
                if(coords.getOrdinate(start, 2) != coords.getOrdinate(finish - 1, 2)) {
                    close = 1;
                }
            }

            CoordinateSequence csRing = geometryFactory.getCoordinateSequenceFactory().create(length + close, dimensions);
            // double area = 0;
            // int sx = offset;
            for (int i = 0; i < length; i++) {
                csRing.setOrdinate(i, 0, coords.getOrdinate(offset, 0));
                csRing.setOrdinate(i, 1, coords.getOrdinate(offset, 1));
                if(dimensions == 3) {
                    csRing.setOrdinate(i, 2, coords.getOrdinate(offset, 2));
                }
                offset++;
            }
            if (close == 1) {
                csRing.setOrdinate(length, 0, coords.getOrdinate(start, 0));
                csRing.setOrdinate(length, 1, coords.getOrdinate(start, 1));
                if(dimensions == 3) {
                    csRing.setOrdinate(length, 2, coords.getOrdinate(start, 2));
                }
            }
            // REVISIT: polygons with only 1 or 2 points are not polygons -
            // geometryFactory will bomb so we skip if we find one.
            if (csRing.size() == 0 || csRing.size() > 3) {
                LinearRing ring = geometryFactory.createLinearRing(csRing);

                if (CoordinateSequences.isCCW(csRing)) {
                    // counter-clockwise
                    holes.add(ring);
View Full Code Here

     * @param buffer
     * @param numPoints
     */
    private CoordinateSequence readCoordinates(final ByteBuffer buffer,
            final int numPoints, final int dimensions) {
        CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(numPoints, dimensions);

        DoubleBuffer dbuffer = buffer.asDoubleBuffer();
        double[] ordinates = new double[numPoints * 2];
        dbuffer.get(ordinates);
        for (int t = 0; t < numPoints; t++) {
            cs.setOrdinate(t, 0, ordinates[t * 2]);
            cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
        }
       
        if (dimensions > 2) {
            // z
            dbuffer.position(dbuffer.position() + 2);
            dbuffer.get(ordinates, 0, numPoints);

            for (int t = 0; t < numPoints; t++) {
                cs.setOrdinate(t, 2, ordinates[t]);
            }
        }

        return cs;
    }
View Full Code Here

       
        final double[] zExtreame = {Double.NaN, Double.NaN};
       
        //write out points here!.. and gather up min and max z values
        for (int ringN = 0; ringN < nrings; ringN++) {
            CoordinateSequence coords = coordinates[ringN];
           
            JTSUtilities.zMinMax(coords, zExtreame);
           
            final int seqSize = coords.size();
            for(int coordN = 0; coordN < seqSize; coordN++){
                buffer.putDouble(coords.getOrdinate(coordN, 0));
                buffer.putDouble(coords.getOrdinate(coordN, 1));
            }
        }
       
        if (shapeType == ShapeType.POLYGONZ) {
          //z     
          if (Double.isNaN(zExtreame[0])) {
            buffer.putDouble(0.0);
            buffer.putDouble(0.0);
          } else {
            buffer.putDouble(zExtreame[0]);
            buffer.putDouble(zExtreame[1]);
          }
         
          for (int ringN = 0; ringN < nrings; ringN++) {
              CoordinateSequence coords = coordinates[ringN];
         
              final int seqSize = coords.size();
              double z;
              for (int coordN = 0; coordN < seqSize; coordN++) {
                  z = coords.getOrdinate(coordN, 2);
                  if (Double.isNaN(z)) {
                      buffer.putDouble(0.0);
                  } else {
                      buffer.putDouble(z);
                  }
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.