Example usage for com.google.common.geometry S2RegionCoverer getCovering

List of usage examples for com.google.common.geometry S2RegionCoverer getCovering

Introduction

In this page you can find the example usage for com.google.common.geometry S2RegionCoverer getCovering.

Prototype

public S2CellUnion getCovering(S2Region region) 

Source Link

Document

Return a normalized cell union that covers the given region and satisfies the restrictions *EXCEPT* for min_level() and level_mod().

Usage

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

public static void main(String[] args) throws ParseException {
    S2Polygon polygon = S2EoProduct.createPolygon(poly);
    //        System.out.println("polygon = " + polygon);

    S2RegionCoverer coverer = new S2RegionCoverer();
    coverer.setMinLevel(0);/*  ww w  .  java 2  s  .  c om*/
    coverer.setMaxLevel(5);
    coverer.setMaxCells(500);
    S2CellUnion covering = coverer.getCovering(polygon);

    final GeometryFactory factory = new GeometryFactory();
    List<S2CellId> s2CellIds = covering.cellIds();
    System.out.println("s2CellIds.size() = " + s2CellIds.size());
    List<Polygon> polys = new ArrayList<>();

    for (S2CellId s2CellId : s2CellIds) {
        //            System.out.println("s2CellId = " + s2CellId);
        ArrayList<double[]> coordList = new ArrayList<double[]>();

        //System.out.println("s2CellId = " + s2CellId);
        S2Cell s2Cell = new S2Cell(s2CellId);
        //System.out.println("s2Cell = " + s2Cell);
        S2LatLng s2LatLng = new S2LatLng(s2Cell.getVertex(0));
        coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() });

        s2LatLng = new S2LatLng(s2Cell.getVertex(1));
        coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() });

        s2LatLng = new S2LatLng(s2Cell.getVertex(2));
        coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() });

        s2LatLng = new S2LatLng(s2Cell.getVertex(3));
        coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() });

        s2LatLng = new S2LatLng(s2Cell.getVertex(0));
        coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() });

        final Coordinate[] coordinates = new Coordinate[coordList.size()];
        for (int i1 = 0; i1 < coordinates.length; i1++) {
            final double[] coord = coordList.get(i1);
            coordinates[i1] = new Coordinate(coord[1], coord[0]);
        }
        Polygon p = factory.createPolygon(factory.createLinearRing(coordinates));
        //System.out.println(p);
        polys.add(p);
    }
    MultiPolygon multiPolygon = factory.createMultiPolygon(polys.toArray(new Polygon[polys.size()]));

    Geometry simplify = TopologyPreservingSimplifier.simplify(multiPolygon, 0.01);
    System.out.println(multiPolygon);
    System.out.println(simplify);
    Geometry origin = new WKTReader().read(poly);
    Geometry both = multiPolygon.union(origin);
    System.out.println(both);

}

From source file:com.bc.inventory.utils.S2Integer.java

public static S2CellUnion createCellUnion(S2Polygon s2polygon, int maxLevel) {
    S2RegionCoverer coverer = new S2RegionCoverer();
    coverer.setMinLevel(0);/*from  www.j  a va2s  .  com*/
    coverer.setMaxLevel(maxLevel);
    coverer.setMaxCells(500);
    return coverer.getCovering(s2polygon);
}

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

@Override
public void createGeo() {
    getPolygon();//w  ww.j a va 2  s .  co m
    S2RegionCoverer coverer = new S2RegionCoverer();
    coverer.setMinLevel(0);
    coverer.setMaxLevel(3);
    coverer.setMaxCells(500);
    cellUnion = coverer.getCovering(polygon);
}

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

public Set<Integer> matchProduct(String testWKT, long windowStartTime, long windowEndTime) {
    S2Region testRegion = new S2WKTReader().read(testWKT);
    S2Polygon testPoly = (S2Polygon) testRegion;
    S2RegionCoverer coverer = new S2RegionCoverer();
    coverer.setMinLevel(3);// w  w  w.j  a  v  a 2  s  . c  o  m
    coverer.setMaxLevel(3);
    coverer.setMaxCells(500);
    S2CellUnion covering = coverer.getCovering(testRegion);
    S2ReverseIndexCreatorMain.S2IntCoverage s2IntCoverage = new S2ReverseIndexCreatorMain.S2IntCoverage(
            covering);

    Set<Integer> candidatesSet = new HashSet<>();
    for (int cellId : s2IntCoverage.intIds) {
        candidatesSet.addAll(reverseProductDB.findInsitu(cellId, windowStartTime, windowEndTime));
    }

    System.out.println("candidatesSet = " + candidatesSet.size());
    List<Integer> uniqueProductList = new ArrayList<>(candidatesSet);

    Set<Integer> matches = new HashSet<>();
    try (StopWatch sw = new StopWatch("  >>load and test polygons")) {
        Collections.sort(uniqueProductList);
        try (DataInputStream dis = new DataInputStream(
                new BufferedInputStream(new FileInputStream(polygonFile)))) {
            int streamPID = 0;
            for (Integer productID : uniqueProductList) {
                while (streamPID < productID) {
                    int numLoopPoints = dis.readInt();
                    dis.skipBytes(numLoopPoints * 3 * 8);
                    streamPID++;
                }
                final int numLoopPoints = dis.readInt();
                final double[] pointData = new double[numLoopPoints * 3];
                for (int i = 0; i < pointData.length; i++) {
                    pointData[i] = dis.readDouble();
                }
                streamPID++;

                S2Polygon s2Polygon = S2IEoProduct.createS2Polygon(pointData);
                if (testPoly.intersects(s2Polygon)) {
                    matches.add(productID);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    return matches;
}