Example usage for com.google.common.geometry S2Cell S2Cell

List of usage examples for com.google.common.geometry S2Cell S2Cell

Introduction

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

Prototype

public S2Cell(S2LatLng ll) 

Source Link

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);/*from w  w  w  .j  a va 2s.  c  o  m*/
    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.amazonaws.geo.s2.internal.S2Manager.java

private static boolean containsGeodataToFind(S2CellId c, S2LatLngRect latLngRect) {
    if (latLngRect != null) {
        return latLngRect.intersects(new S2Cell(c));
    }//from   w w  w . j  a  v a  2s  .c  o m

    return false;
}

From source file:com.amazonaws.geo.s2.internal.S2Manager.java

public static long generateGeohash(GeoPoint geoPoint) {
    S2LatLng latLng = S2LatLng.fromDegrees(geoPoint.getLatitude(), geoPoint.getLongitude());
    S2Cell cell = new S2Cell(latLng);
    S2CellId cellId = cell.id();/*from   w w  w  . jav a  2s.  c  om*/

    return cellId.id();
}

From source file:org.apache.lucene.spatial.spatial4j.Geo3dShapeFactory.java

@Override
public Shape getS2CellShape(S2CellId cellId) {
    S2Cell cell = new S2Cell(cellId);
    GeoPoint point1 = getGeoPoint(cell.getVertexRaw(0));
    GeoPoint point2 = getGeoPoint(cell.getVertexRaw(1));
    GeoPoint point3 = getGeoPoint(cell.getVertexRaw(2));
    GeoPoint point4 = getGeoPoint(cell.getVertexRaw(3));
    return new Geo3dShape<>(GeoS2ShapeFactory.makeGeoS2Shape(planetModel, point1, point2, point3, point4),
            context);/*from w w w  .  j a  va2s  .  c  o  m*/
}