Search in sources :

Example 11 with SqlNullable

use of io.trino.spi.function.SqlNullable in project trino by trinodb.

the class GeoFunctions method stOverlaps.

@SqlNullable
@Description("Returns TRUE if the Geometries share space, are of the same dimension, but are not completely contained by each other")
@ScalarFunction("ST_Overlaps")
@SqlType(BOOLEAN)
public static Boolean stOverlaps(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::intersect)) {
        return false;
    }
    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.overlaps(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 12 with SqlNullable

use of io.trino.spi.function.SqlNullable in project trino by trinodb.

the class GeoFunctions method stNumInteriorRings.

@SqlNullable
@Description("Returns the cardinality of the collection of interior rings of a polygon")
@ScalarFunction("ST_NumInteriorRing")
@SqlType(BIGINT)
public static Long stNumInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_NumInteriorRing", geometry, EnumSet.of(POLYGON));
    if (geometry.isEmpty()) {
        return null;
    }
    return Long.valueOf(((OGCPolygon) geometry).numInteriorRing());
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 13 with SqlNullable

use of io.trino.spi.function.SqlNullable in project trino by trinodb.

the class GeoFunctions method stEquals.

@SqlNullable
@Description("Returns TRUE if the given geometries represent the same geometry")
@ScalarFunction("ST_Equals")
@SqlType(BOOLEAN)
public static Boolean stEquals(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.Equals(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 14 with SqlNullable

use of io.trino.spi.function.SqlNullable in project trino by trinodb.

the class GeoFunctions method stMultiPoint.

@SqlNullable
@Description("Returns a multi-point geometry formed from input points")
@ScalarFunction("ST_MultiPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) {
    MultiPoint multipoint = new MultiPoint();
    for (int i = 0; i < input.getPositionCount(); i++) {
        if (input.isNull(i)) {
            throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: null at index %s", i + 1));
        }
        Slice slice = GEOMETRY.getSlice(input, i);
        OGCGeometry geometry = deserialize(slice);
        if (!(geometry instanceof OGCPoint)) {
            throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: geometry is not a point: %s at index %s", geometry.geometryType(), i + 1));
        }
        OGCPoint point = (OGCPoint) geometry;
        if (point.isEmpty()) {
            throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: empty point at index %s", i + 1));
        }
        multipoint.add(point.X(), point.Y());
    }
    if (multipoint.getPointCount() == 0) {
        return null;
    }
    return serialize(createFromEsriGeometry(multipoint, null, true));
}
Also used : MultiPoint(com.esri.core.geometry.MultiPoint) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) TrinoException(io.trino.spi.TrinoException) MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 15 with SqlNullable

use of io.trino.spi.function.SqlNullable in project trino by trinodb.

the class GeoFunctions method stInteriorRings.

@SqlNullable
@Description("Returns an array of interior rings of a polygon")
@ScalarFunction("ST_InteriorRings")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_InteriorRings", geometry, EnumSet.of(POLYGON));
    if (geometry.isEmpty()) {
        return null;
    }
    OGCPolygon polygon = (OGCPolygon) geometry;
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, polygon.numInteriorRing());
    for (int i = 0; i < polygon.numInteriorRing(); i++) {
        GEOMETRY.writeSlice(blockBuilder, serialize(polygon.interiorRingN(i)));
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) BlockBuilder(io.trino.spi.block.BlockBuilder) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Aggregations

SqlNullable (io.trino.spi.function.SqlNullable)56 SqlType (io.trino.spi.function.SqlType)56 ScalarFunction (io.trino.spi.function.ScalarFunction)44 Description (io.trino.spi.function.Description)38 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)32 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)14 JsonParser (com.fasterxml.jackson.core.JsonParser)14 TrinoException (io.trino.spi.TrinoException)14 JsonUtil.createJsonParser (io.trino.util.JsonUtil.createJsonParser)14 IOException (java.io.IOException)14 MultiPoint (com.esri.core.geometry.MultiPoint)12 Point (com.esri.core.geometry.Point)12 BlockBuilder (io.trino.spi.block.BlockBuilder)10 ScalarOperator (io.trino.spi.function.ScalarOperator)8 JsonCastException (io.trino.util.JsonCastException)8 LiteralParameters (io.trino.spi.function.LiteralParameters)7 JsonToken (com.fasterxml.jackson.core.JsonToken)6 MultiPath (com.esri.core.geometry.MultiPath)4 MultiVertexGeometry (com.esri.core.geometry.MultiVertexGeometry)4 Slice (io.airlift.slice.Slice)4