use of io.trino.spi.function.SqlType 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);
}
use of io.trino.spi.function.SqlType in project trino by trinodb.
the class GeoFunctions method stIntersection.
@Description("Returns the Geometry value that represents the point set intersection of two Geometries")
@ScalarFunction("ST_Intersection")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stIntersection(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
if (deserializeType(left) == GeometrySerializationType.ENVELOPE && deserializeType(right) == GeometrySerializationType.ENVELOPE) {
Envelope leftEnvelope = deserializeEnvelope(left);
Envelope rightEnvelope = deserializeEnvelope(right);
// Envelope#intersect updates leftEnvelope to the intersection of the two envelopes
if (!leftEnvelope.intersect(rightEnvelope)) {
return EMPTY_POLYGON;
}
Envelope intersection = leftEnvelope;
if (intersection.getXMin() == intersection.getXMax()) {
if (intersection.getYMin() == intersection.getYMax()) {
return serialize(createFromEsriGeometry(new Point(intersection.getXMin(), intersection.getXMax()), null));
}
return serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMin(), intersection.getYMax())), null));
}
if (intersection.getYMin() == intersection.getYMax()) {
return serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMax(), intersection.getYMin())), null));
}
return serialize(intersection);
}
OGCGeometry leftGeometry = deserialize(left);
OGCGeometry rightGeometry = deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return serialize(leftGeometry.intersection(rightGeometry));
}
use of io.trino.spi.function.SqlType 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());
}
use of io.trino.spi.function.SqlType 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.SqlType 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));
}
Aggregations