use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
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.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class GeoFunctions method stNumGeometries.
@Description("Returns the cardinality of the geometry collection")
@ScalarFunction("ST_NumGeometries")
@SqlType(INTEGER)
public static long stNumGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = deserialize(input);
if (geometry.isEmpty()) {
return 0;
}
GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
if (!type.isMultitype()) {
return 1;
}
return ((OGCGeometryCollection) geometry).numGeometries();
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class GeoFunctions method stTouches.
@SqlNullable
@Description("Returns TRUE if the geometries have at least one point in common, but their interiors do not intersect")
@ScalarFunction("ST_Touches")
@SqlType(BOOLEAN)
public static Boolean stTouches(@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.touches(rightGeometry);
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class GeoFunctions method stLength.
@Description("Returns the length of a LineString or Multi-LineString using Euclidean measurement on a 2D plane (based on spatial ref) in projected units")
@ScalarFunction("ST_Length")
@SqlType(DOUBLE)
public static double stLength(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = deserialize(input);
validateType("ST_Length", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING));
return geometry.getEsriGeometry().calculateLength2D();
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class GeoFunctions method stDistance.
@SqlNullable
@Description("Returns the 2-dimensional cartesian minimum distance (based on spatial ref) between two geometries in projected units")
@ScalarFunction("ST_Distance")
@SqlType(DOUBLE)
public static Double stDistance(@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.isEmpty() || rightGeometry.isEmpty() ? null : leftGeometry.distance(rightGeometry);
}
Aggregations