use of io.trino.spi.function.ScalarFunction 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);
}
use of io.trino.spi.function.ScalarFunction 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));
}
use of io.trino.spi.function.ScalarFunction in project trino by trinodb.
the class GeoFunctions method stDifference.
@Description("Returns the Geometry value that represents the point set difference of two geometries")
@ScalarFunction("ST_Difference")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stDifference(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
OGCGeometry leftGeometry = deserialize(left);
OGCGeometry rightGeometry = deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return serialize(leftGeometry.difference(rightGeometry));
}
use of io.trino.spi.function.ScalarFunction 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();
}
use of io.trino.spi.function.ScalarFunction in project trino by trinodb.
the class GeoFunctions method stPolygon.
@Description("Returns a Geometry type Polygon object from Well-Known Text representation (WKT)")
@ScalarFunction("ST_Polygon")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stPolygon(@SqlType(VARCHAR) Slice input) {
OGCGeometry geometry = geometryFromText(input);
validateType("ST_Polygon", geometry, EnumSet.of(POLYGON));
return serialize(geometry);
}
Aggregations