use of io.trino.spi.function.ScalarFunction 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();
}
use of io.trino.spi.function.ScalarFunction 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();
}
use of io.trino.spi.function.ScalarFunction 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);
}
use of io.trino.spi.function.ScalarFunction 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);
}
use of io.trino.spi.function.ScalarFunction 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();
}
Aggregations