use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class GeoFunctions method stY.
@SqlNullable
@Description("Return the Y coordinate of the point")
@ScalarFunction("ST_Y")
@SqlType(DOUBLE)
public static Double stY(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
validateType("ST_Y", geometry, EnumSet.of(POINT));
if (geometry.isEmpty()) {
return null;
}
return ((org.locationtech.jts.geom.Point) geometry).getY();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class GeoFunctions method stIsClosed.
@SqlNullable
@Description("Returns TRUE if the LineString or Multi-LineString's start and end points are coincident")
@ScalarFunction("ST_IsClosed")
@SqlType(BOOLEAN)
public static Boolean stIsClosed(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
validateType("ST_IsClosed", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING));
if (geometry instanceof LineString) {
return ((LineString) geometry).isClosed();
} else if (geometry instanceof MultiLineString) {
return ((MultiLineString) geometry).isClosed();
}
// This would be handled in validateType, but for completeness.
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid type for isClosed: %s", geometry.getGeometryType()));
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class GeoFunctions method lineInterpolatePoint.
@Description("Returns the point in the line at the fractional length.")
@ScalarFunction("line_interpolate_point")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice lineInterpolatePoint(@SqlType(GEOMETRY_TYPE_NAME) Slice lineSlice, @SqlType(DOUBLE) double fraction) {
if (!(0.0 <= fraction && fraction <= 1.0)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("line_interpolate_point: Fraction must be between 0 and 1, but is %s", fraction));
}
Geometry geometry = deserialize(lineSlice);
validateType("line_interpolate_point", geometry, ImmutableSet.of(LINE_STRING));
LineString line = (LineString) geometry;
if (line.isEmpty()) {
return serialize(createJtsEmptyPoint());
}
org.locationtech.jts.geom.Coordinate coordinate = new LengthIndexedLine(line).extractPoint(fraction * line.getLength());
return serialize(createJtsPoint(coordinate));
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
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 = EsriGeometrySerde.deserialize(left);
OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.touches(rightGeometry);
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class GeoFunctions method stStartPoint.
@SqlNullable
@Description("Returns the first point of a LINESTRING geometry as a Point")
@ScalarFunction("ST_StartPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stStartPoint(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
validateType("ST_StartPoint", geometry, EnumSet.of(LINE_STRING));
if (geometry.isEmpty()) {
return null;
}
return serialize(((LineString) geometry).getStartPoint());
}
Aggregations