Search in sources :

Example 1 with GeometryCursor

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

the class SphericalGeoFunctions method toSphericalGeography.

@Description("Converts a Geometry object to a SphericalGeography object")
@ScalarFunction("to_spherical_geography")
@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME)
public static Slice toSphericalGeography(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    // "every point in input is in range" <=> "the envelope of input is in range"
    Envelope envelope = deserializeEnvelope(input);
    if (!envelope.isEmpty()) {
        checkLatitude(envelope.getYMin());
        checkLatitude(envelope.getYMax());
        checkLongitude(envelope.getXMin());
        checkLongitude(envelope.getXMax());
    }
    OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
    if (geometry.is3D()) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert 3D geometry to a spherical geography");
    }
    GeometryCursor cursor = geometry.getEsriGeometryCursor();
    while (true) {
        com.esri.core.geometry.Geometry subGeometry = cursor.next();
        if (subGeometry == null) {
            break;
        }
        if (!GEOMETRY_TYPES_FOR_SPHERICAL_GEOGRAPHY.contains(subGeometry.getType())) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert geometry of this type to spherical geography: " + subGeometry.getType());
        }
    }
    return input;
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometryCursor(com.esri.core.geometry.GeometryCursor) PrestoException(com.facebook.presto.spi.PrestoException) Geometry(com.esri.core.geometry.Geometry) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 2 with GeometryCursor

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

the class GeometryUtils method accelerateGeometry.

public static void accelerateGeometry(OGCGeometry ogcGeometry, Operator relateOperator, Geometry.GeometryAccelerationDegree accelerationDegree) {
    // Recurse into GeometryCollections
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    while (true) {
        Geometry esriGeometry = cursor.next();
        if (esriGeometry == null) {
            break;
        }
        relateOperator.accelerateGeometry(esriGeometry, null, accelerationDegree);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) Geometry(com.esri.core.geometry.Geometry) GeometryCursor(com.esri.core.geometry.GeometryCursor)

Example 3 with GeometryCursor

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

the class GeometryUtils method getPointCount.

public static int getPointCount(OGCGeometry ogcGeometry) {
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    int points = 0;
    while (true) {
        com.esri.core.geometry.Geometry geometry = cursor.next();
        if (geometry == null) {
            return points;
        }
        if (geometry.isEmpty()) {
            continue;
        }
        if (geometry instanceof Point) {
            points++;
        } else {
            points += ((MultiVertexGeometry) geometry).getPointCount();
        }
    }
}
Also used : GeometryCursor(com.esri.core.geometry.GeometryCursor) Geometry(com.esri.core.geometry.Geometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point)

Example 4 with GeometryCursor

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

the class GeometryUtils method getEnvelope.

public static Envelope getEnvelope(OGCGeometry ogcGeometry) {
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    Envelope overallEnvelope = new Envelope();
    while (true) {
        Geometry geometry = cursor.next();
        if (geometry == null) {
            return overallEnvelope;
        }
        Envelope envelope = new Envelope();
        geometry.queryEnvelope(envelope);
        overallEnvelope.merge(envelope);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) Geometry(com.esri.core.geometry.Geometry) GeometryCursor(com.esri.core.geometry.GeometryCursor) Envelope(com.esri.core.geometry.Envelope)

Example 5 with GeometryCursor

use of com.esri.core.geometry.GeometryCursor 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)

Aggregations

GeometryCursor (com.esri.core.geometry.GeometryCursor)5 Geometry (com.esri.core.geometry.Geometry)4 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)4 Envelope (com.esri.core.geometry.Envelope)2 MultiVertexGeometry (com.esri.core.geometry.MultiVertexGeometry)2 Point (com.esri.core.geometry.Point)2 ListeningGeometryCursor (com.esri.core.geometry.ListeningGeometryCursor)1 OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)1 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)1 GeometryUtils.createJtsEmptyPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint)1 GeometryUtils.createJtsMultiPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint)1 GeometryUtils.createJtsPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsPoint)1 EsriGeometrySerde.deserializeEnvelope (com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Description (com.facebook.presto.spi.function.Description)1 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)1 SqlType (com.facebook.presto.spi.function.SqlType)1 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 ArrayList (java.util.ArrayList)1