Search in sources :

Example 56 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable in project presto by prestodb.

the class GeoFunctions method stWithin.

@SqlNullable
@Description("Returns TRUE if the geometry A is completely inside geometry B")
@ScalarFunction("ST_Within")
@SqlType(BOOLEAN)
public static Boolean stWithin(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(right, left, Envelope::contains)) {
        return false;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.within(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 57 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable in project presto by prestodb.

the class GeoFunctions method stDisjoint.

@SqlNullable
@Description("Returns TRUE if the Geometries do not spatially intersect - if they do not share any space together")
@ScalarFunction("ST_Disjoint")
@SqlType(BOOLEAN)
public static Boolean stDisjoint(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::intersect)) {
        return true;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.disjoint(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 58 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable in project presto by prestodb.

the class GeoFunctions method stContains.

@SqlNullable
@Description("Returns TRUE if and only if no points of right lie in the exterior of left, and at least one point of the interior of left lies in the interior of right")
@ScalarFunction("ST_Contains")
@SqlType(BOOLEAN)
public static Boolean stContains(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::contains)) {
        return false;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.contains(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 59 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable in project presto by prestodb.

the class GeoFunctions method spatialPartitions.

@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a geometry representing a set of points within specified distance from the input geometry")
@SqlType("array(int)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(GEOMETRY_TYPE_NAME) Slice geometry, @SqlType(DOUBLE) double distance) {
    if (isNaN(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN");
    }
    if (isInfinite(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is infinite");
    }
    if (distance < 0) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative");
    }
    Envelope envelope = deserializeEnvelope(geometry);
    if (envelope.isEmpty()) {
        return null;
    }
    Rectangle expandedEnvelope2D = new Rectangle(envelope.getXMin() - distance, envelope.getYMin() - distance, envelope.getXMax() + distance, envelope.getYMax() + distance);
    return spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) PrestoException(com.facebook.presto.spi.PrestoException) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 60 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable in project presto by prestodb.

the class GeoFunctions method stX.

@SqlNullable
@Description("Return the X coordinate of the point")
@ScalarFunction("ST_X")
@SqlType(DOUBLE)
public static Double stX(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_X", geometry, EnumSet.of(POINT));
    if (geometry.isEmpty()) {
        return null;
    }
    return ((org.locationtech.jts.geom.Point) geometry).getX();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) 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) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

SqlNullable (com.facebook.presto.spi.function.SqlNullable)61 SqlType (com.facebook.presto.spi.function.SqlType)61 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)44 Description (com.facebook.presto.spi.function.Description)37 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)29 PrestoException (com.facebook.presto.spi.PrestoException)17 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)15 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)15 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)15 Geometry (org.locationtech.jts.geom.Geometry)15 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)14 JsonParser (com.fasterxml.jackson.core.JsonParser)14 IOException (java.io.IOException)14 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)9 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)8 JsonCastException (com.facebook.presto.util.JsonCastException)8 Slice (io.airlift.slice.Slice)8 Point (com.esri.core.geometry.Point)7 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)7 TypeParameter (com.facebook.presto.spi.function.TypeParameter)7