Example usage for com.google.common.geometry S2Loop vertex

List of usage examples for com.google.common.geometry S2Loop vertex

Introduction

In this page you can find the example usage for com.google.common.geometry S2Loop vertex.

Prototype

public S2Point vertex(int i) 

Source Link

Document

For convenience, we make two entire copies of the vertex list available: vertex(n..2*n-1) is mapped to vertex(0..n-1), where n == numVertices().

Usage

From source file:com.bc.geometry.s2.S2Util.java

public static double[][] toXYZArray(S2Polygon polygon) {
    final List<S2Point> vertices = new ArrayList<>();
    final int numLoops = polygon.numLoops();
    for (int i = 0; i < numLoops; i++) {
        final S2Loop loop = polygon.loop(i);
        final int numVertices = loop.numVertices();
        for (int k = 0; k < numVertices; k++) {
            vertices.add(loop.vertex(k));
        }//from  w w  w  .  j  ava2  s. c om
    }

    final int numVertices = vertices.size();
    final double[][] xyzArray = new double[numVertices][3];
    for (int i = 0; i < numVertices; i++) {
        final double[] vector = new double[3];
        final S2Point s2Point = vertices.get(i);
        vector[0] = s2Point.getX();
        vector[1] = s2Point.getY();
        vector[2] = s2Point.getZ();

        xyzArray[i] = vector;
    }

    return xyzArray;
}

From source file:com.bc.geometry.s2.S2WKTWriter.java

private static String writePolygonWkt(S2Polygon polygon) {
    final StringBuilder builder = new StringBuilder();
    builder.append("POLYGON((");
    final int numLoops = polygon.numLoops();
    for (int i = 0; i < numLoops; i++) {
        final S2Loop loop = polygon.loop(i);
        final int numVertices = loop.numVertices();
        for (int k = 0; k < numVertices; k++) {
            appendWktPoint(loop.vertex(k), builder);
            builder.append(",");
        }//from  w  w w .  ja  v a 2s .  c  o  m
        appendWktPoint(loop.vertex(0), builder);
    }

    builder.append("))");
    return builder.toString();
}

From source file:com.bc.fiduceo.geometry.s2.BcS2Polygon.java

static ArrayList<Point> extractPoints(S2Polygon googlePolygon) {
    final ArrayList<Point> coordinates = new ArrayList<>();
    final int numLoops = googlePolygon.numLoops();
    for (int i = 0; i < numLoops; i++) {
        final S2Loop loop = googlePolygon.loop(i);
        final int numVertices = loop.numVertices();
        for (int k = 0; k < numVertices; k++) {
            final S2Point googlePoint = loop.vertex(k);
            coordinates.add(BcS2Point.createFrom(googlePoint));
        }//from   w  ww.  j  a v  a  2 s  . c  o m

        // close loop - outside world expects this tb 2016-03-03
        final S2Point googlePoint = loop.vertex(0);
        coordinates.add(BcS2Point.createFrom(googlePoint));
    }
    return coordinates;
}

From source file:org.esa.beam.occci.S2EoProduct.java

private static String singleLoopToString(S2Polygon s2polygon) {
    S2Loop loop = s2polygon.loop(0);
    int numVertices = loop.numVertices();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < numVertices; i++) {
        sb.append(loop.vertex(i).toString());
        if (i < numVertices - 1) {
            sb.append(";");
        }/*from  w  w  w  . j a  v a  2  s .c o m*/
    }
    return sb.toString();
}

From source file:org.esa.beam.occci.S2EoProduct.java

public void writePolygone(DataOutputStream dos) throws IOException {
    S2Loop loop = polygon.loop(0);
    int numVertices = loop.numVertices();
    dos.writeInt(numVertices);//  w w  w  .java 2  s  .  c om

    for (int i = 0; i < numVertices; i++) {
        S2Point vertex = loop.vertex(i);
        try {
            double x = (double) S2X.get(vertex);
            double y = (double) S2Y.get(vertex);
            double z = (double) S2Z.get(vertex);
            dos.writeDouble(x);
            dos.writeDouble(y);
            dos.writeDouble(z);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}