Search in sources :

Example 6 with OGCConcreteGeometryCollection

use of com.esri.core.geometry.ogc.OGCConcreteGeometryCollection in project presto by prestodb.

the class GeoFunctions method stUnion.

private static Slice stUnion(Iterable<Slice> slices) {
    // The current state of Esri/geometry-api-java does not allow support for multiple dimensions being
    // fed to the union operator without dropping the lower dimensions:
    // https://github.com/Esri/geometry-api-java/issues/199
    // When operating over a collection of geometries, it is more efficient to reuse the same operator
    // for the entire operation.  Therefore, split the inputs and operators by dimension, and then union
    // each dimension's result at the end.
    ListeningGeometryCursor[] cursorsByDimension = new ListeningGeometryCursor[NUMBER_OF_DIMENSIONS];
    GeometryCursor[] operatorsByDimension = new GeometryCursor[NUMBER_OF_DIMENSIONS];
    setAll(cursorsByDimension, i -> new ListeningGeometryCursor());
    setAll(operatorsByDimension, i -> OperatorUnion.local().execute(cursorsByDimension[i], null, null));
    Iterator<Slice> slicesIterator = slices.iterator();
    if (!slicesIterator.hasNext()) {
        return null;
    }
    while (slicesIterator.hasNext()) {
        Slice slice = slicesIterator.next();
        // Ignore null inputs
        if (slice.getInput().available() == 0) {
            continue;
        }
        for (OGCGeometry geometry : flattenCollection(EsriGeometrySerde.deserialize(slice))) {
            int dimension = geometry.dimension();
            cursorsByDimension[dimension].tick(geometry.getEsriGeometry());
            operatorsByDimension[dimension].tock();
        }
    }
    List<OGCGeometry> outputs = new ArrayList<>();
    for (GeometryCursor operator : operatorsByDimension) {
        OGCGeometry unionedGeometry = createFromEsriGeometry(operator.next(), null);
        if (unionedGeometry != null) {
            outputs.add(unionedGeometry);
        }
    }
    if (outputs.size() == 1) {
        return EsriGeometrySerde.serialize(outputs.get(0));
    }
    return EsriGeometrySerde.serialize(new OGCConcreteGeometryCollection(outputs, null).flattenAndRemoveOverlaps().reduceFromMulti());
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ListeningGeometryCursor(com.esri.core.geometry.ListeningGeometryCursor) GeometryCursor(com.esri.core.geometry.GeometryCursor) ListeningGeometryCursor(com.esri.core.geometry.ListeningGeometryCursor) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) ArrayList(java.util.ArrayList) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint)

Example 7 with OGCConcreteGeometryCollection

use of com.esri.core.geometry.ogc.OGCConcreteGeometryCollection in project pigeon by aseldawy.

the class ConvexHull method convexHull.

protected static OGCGeometry convexHull(Tuple input) throws ExecException {
    DataBag values = (DataBag) input.get(0);
    if (values.size() == 0)
        return null;
    ArrayList<OGCGeometry> all_geoms = new ArrayList<OGCGeometry>();
    for (Tuple one_geom : values) {
        OGCGeometry parsedGeom = geometryParser.parseGeom(one_geom.get(0));
        all_geoms.add(parsedGeom);
    }
    // Do a convex null of all_geometries
    OGCGeometryCollection geom_collection = new OGCConcreteGeometryCollection(all_geoms, all_geoms.get(0).getEsriSpatialReference());
    return geom_collection.convexHull();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) DataBag(org.apache.pig.data.DataBag) OGCGeometryCollection(com.esri.core.geometry.ogc.OGCGeometryCollection) ArrayList(java.util.ArrayList) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) Tuple(org.apache.pig.data.Tuple)

Aggregations

OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)7 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)6 ArrayList (java.util.ArrayList)5 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)4 DataBag (org.apache.pig.data.DataBag)4 Tuple (org.apache.pig.data.Tuple)4 Point (com.esri.core.geometry.Point)3 GeometryCursor (com.esri.core.geometry.GeometryCursor)1 Line (com.esri.core.geometry.Line)1 ListeningGeometryCursor (com.esri.core.geometry.ListeningGeometryCursor)1 MultiPath (com.esri.core.geometry.MultiPath)1 MultiPoint (com.esri.core.geometry.MultiPoint)1 Polygon (com.esri.core.geometry.Polygon)1 Polyline (com.esri.core.geometry.Polyline)1 Segment (com.esri.core.geometry.Segment)1 OGCLineString (com.esri.core.geometry.ogc.OGCLineString)1 OGCMultiPoint (com.esri.core.geometry.ogc.OGCMultiPoint)1 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)1 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)1 GeometryType (com.facebook.presto.geospatial.GeometryType)1