Search in sources :

Example 41 with SqlType

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

the class GeoFunctions method stEndPoint.

@SqlNullable
@Description("Returns the last point of a LINESTRING geometry as a Point")
@ScalarFunction("ST_EndPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stEndPoint(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_EndPoint", geometry, EnumSet.of(LINE_STRING));
    if (geometry.isEmpty()) {
        return null;
    }
    MultiPath lines = (MultiPath) geometry.getEsriGeometry();
    SpatialReference reference = geometry.getEsriSpatialReference();
    return serialize(createFromEsriGeometry(lines.getPoint(lines.getPointCount() - 1), reference));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiPath(com.esri.core.geometry.MultiPath) SpatialReference(com.esri.core.geometry.SpatialReference) 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 42 with SqlType

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

the class GeoFunctions method stGeometries.

@SqlNullable
@Description("Returns an array of geometries in the specified collection")
@ScalarFunction("ST_Geometries")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (!type.isMultitype()) {
        BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1);
        GEOMETRY.writeSlice(blockBuilder, serialize(geometry));
        return blockBuilder.build();
    }
    OGCGeometryCollection collection = (OGCGeometryCollection) geometry;
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.numGeometries());
    for (int i = 0; i < collection.numGeometries(); i++) {
        GEOMETRY.writeSlice(blockBuilder, serialize(collection.geometryN(i)));
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometryType(io.trino.geospatial.GeometryType) OGCGeometryCollection(com.esri.core.geometry.ogc.OGCGeometryCollection) 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 43 with SqlType

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

the class GeoFunctions method stIntersects.

@SqlNullable
@Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)")
@ScalarFunction("ST_Intersects")
@SqlType(BOOLEAN)
public static Boolean stIntersects(@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.intersects(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 44 with SqlType

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

the class GeoFunctions method lineInterpolatePoints.

@SqlNullable
@Description("Returns an array of Points interpolated along a LineString.")
@ScalarFunction("line_interpolate_points")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block lineInterpolatePoints(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.DOUBLE) double fractionStep) {
    OGCGeometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    List<Point> interpolatedPoints = interpolatePoints(geometry, fractionStep, true);
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, interpolatedPoints.size());
    for (Point point : interpolatedPoints) {
        GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(point, null)));
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) 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 45 with SqlType

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

the class GeoFunctions method stEnvelopeAsPts.

@SqlNullable
@Description("Returns the lower left and upper right corners of bounding rectangular polygon of a Geometry")
@ScalarFunction("ST_EnvelopeAsPts")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stEnvelopeAsPts(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
    Point lowerLeftCorner = new Point(envelope.getXMin(), envelope.getYMin());
    Point upperRightCorner = new Point(envelope.getXMax(), envelope.getYMax());
    GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(lowerLeftCorner, null, false)));
    GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(upperRightCorner, null, false)));
    return blockBuilder.build();
}
Also used : MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) GeometrySerde.deserializeEnvelope(io.trino.geospatial.serde.GeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) 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

SqlType (io.trino.spi.function.SqlType)176 ScalarFunction (io.trino.spi.function.ScalarFunction)107 Description (io.trino.spi.function.Description)90 LiteralParameters (io.trino.spi.function.LiteralParameters)60 SqlNullable (io.trino.spi.function.SqlNullable)56 BlockBuilder (io.trino.spi.block.BlockBuilder)52 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)46 TrinoException (io.trino.spi.TrinoException)37 Constraint (io.trino.type.Constraint)23 Slice (io.airlift.slice.Slice)22 TypeParameter (io.trino.spi.function.TypeParameter)21 Point (com.esri.core.geometry.Point)17 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)17 MultiPoint (com.esri.core.geometry.MultiPoint)15 JsonParser (com.fasterxml.jackson.core.JsonParser)14 JsonUtil.createJsonParser (io.trino.util.JsonUtil.createJsonParser)14 IOException (java.io.IOException)14 ScalarOperator (io.trino.spi.function.ScalarOperator)13 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)11 Matcher (io.airlift.joni.Matcher)9