Search in sources :

Example 21 with Description

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

the class GeoFunctions method stInteriorRingN.

@SqlNullable
@Description("Returns the interior ring element at the specified index (indices start at 1)")
@ScalarFunction("ST_InteriorRingN")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stInteriorRingN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_InteriorRingN", geometry, EnumSet.of(POLYGON));
    OGCPolygon polygon = (OGCPolygon) geometry;
    if (index < 1 || index > polygon.numInteriorRing()) {
        return null;
    }
    OGCGeometry interiorRing = polygon.interiorRingN(toIntExact(index) - 1);
    return serialize(interiorRing);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) 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 22 with Description

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

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 = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.disjoint(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 23 with Description

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

the class GeoFunctions method stIsRing.

@SqlNullable
@Description("Returns TRUE if and only if the line is closed and simple")
@ScalarFunction("ST_IsRing")
@SqlType(BOOLEAN)
public static Boolean stIsRing(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_IsRing", geometry, EnumSet.of(LINE_STRING));
    OGCLineString line = (OGCLineString) geometry;
    return line.isClosed() && line.isSimple();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCLineString(com.esri.core.geometry.ogc.OGCLineString) 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 24 with Description

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

the class GeoFunctions method stPoints.

@SqlNullable
@Description("Returns an array of points in a geometry")
@ScalarFunction("ST_Points")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stPoints(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = JtsGeometrySerde.deserialize(input);
    validateType("ST_Points", geometry, VALID_TYPES_FOR_ST_POINTS);
    if (geometry.isEmpty()) {
        return null;
    }
    int pointCount = geometry.getNumPoints();
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, pointCount);
    buildPointsBlock(geometry, blockBuilder);
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) GeometryUtils.jsonFromJtsGeometry(io.trino.geospatial.GeometryUtils.jsonFromJtsGeometry) Geometry(org.locationtech.jts.geom.Geometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) 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)

Example 25 with Description

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

the class GeoFunctions method geometryFromHadoopShape.

@Description("Returns a Geometry type object from Spatial Framework for Hadoop representation")
@ScalarFunction("geometry_from_hadoop_shape")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice geometryFromHadoopShape(@SqlType(VARBINARY) Slice input) {
    requireNonNull(input, "input is null");
    try {
        OGCGeometry geometry = OGCGeometry.fromEsriShape(getShapeByteBuffer(input));
        String wkt = geometryToWkt(geometry.getEsriGeometry(), getWktExportFlags(input));
        return serialize(OGCGeometry.fromText(wkt));
    } catch (IndexOutOfBoundsException | UnsupportedOperationException | IllegalArgumentException e) {
        throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "Invalid Hadoop shape", e);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) TrinoException(io.trino.spi.TrinoException) OGCLineString(com.esri.core.geometry.ogc.OGCLineString) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Aggregations

Description (io.trino.spi.function.Description)92 ScalarFunction (io.trino.spi.function.ScalarFunction)90 SqlType (io.trino.spi.function.SqlType)90 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)46 SqlNullable (io.trino.spi.function.SqlNullable)38 LiteralParameters (io.trino.spi.function.LiteralParameters)19 Constraint (io.trino.type.Constraint)18 Point (com.esri.core.geometry.Point)17 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)17 Slice (io.airlift.slice.Slice)17 BlockBuilder (io.trino.spi.block.BlockBuilder)16 MultiPoint (com.esri.core.geometry.MultiPoint)15 TrinoException (io.trino.spi.TrinoException)15 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)8 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)8 Matcher (io.airlift.joni.Matcher)7 GeometryType (io.trino.geospatial.GeometryType)7 Envelope (com.esri.core.geometry.Envelope)5 MultiPath (com.esri.core.geometry.MultiPath)5 MultiVertexGeometry (com.esri.core.geometry.MultiVertexGeometry)5