use of com.facebook.presto.spi.function.Description in project presto by prestodb.
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) {
Geometry geometry = deserialize(input);
validateType("ST_InteriorRings", geometry, EnumSet.of(POLYGON));
if (geometry.isEmpty()) {
return null;
}
org.locationtech.jts.geom.Polygon polygon = (org.locationtech.jts.geom.Polygon) geometry;
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, polygon.getNumInteriorRing());
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
GEOMETRY.writeSlice(blockBuilder, serialize((LineString) polygon.getInteriorRingN(i)));
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class GeoFunctions method parseLine.
@Description("Returns a Geometry type LineString object from Well-Known Text representation (WKT)")
@ScalarFunction("ST_LineFromText")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice parseLine(@SqlType(VARCHAR) Slice input) {
Geometry geometry = jtsGeometryFromWkt(input.toStringUtf8());
validateType("ST_LineFromText", geometry, EnumSet.of(LINE_STRING));
return serialize(geometry);
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class GeoFunctions method lineLocatePoint.
@SqlNullable
@Description("Returns a float between 0 and 1 representing the location of the closest point on the LineString to the given Point, as a fraction of total 2d line length.")
@ScalarFunction("line_locate_point")
@SqlType(DOUBLE)
public static Double lineLocatePoint(@SqlType(GEOMETRY_TYPE_NAME) Slice lineSlice, @SqlType(GEOMETRY_TYPE_NAME) Slice pointSlice) {
Geometry line = deserialize(lineSlice);
Geometry point = deserialize(pointSlice);
if (line.isEmpty() || point.isEmpty()) {
return null;
}
GeometryType lineType = GeometryType.getForJtsGeometryType(line.getGeometryType());
if (lineType != GeometryType.LINE_STRING && lineType != GeometryType.MULTI_LINE_STRING) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("First argument to line_locate_point must be a LineString or a MultiLineString. Got: %s", line.getGeometryType()));
}
GeometryType pointType = GeometryType.getForJtsGeometryType(point.getGeometryType());
if (pointType != GeometryType.POINT) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Second argument to line_locate_point must be a Point. Got: %s", point.getGeometryType()));
}
return new LengthIndexedLine(line).indexOf(point.getCoordinate()) / line.getLength();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
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 = EsriGeometrySerde.deserialize(input);
validateType("ST_IsRing", geometry, EnumSet.of(LINE_STRING));
OGCLineString line = (OGCLineString) geometry;
return line.isClosed() && line.isSimple();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
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) {
Geometry geometry = deserialize(input);
validateType("ST_InteriorRingN", geometry, EnumSet.of(POLYGON));
org.locationtech.jts.geom.Polygon polygon = (org.locationtech.jts.geom.Polygon) geometry;
if (index < 1 || index > polygon.getNumInteriorRing()) {
return null;
}
return serialize(polygon.getInteriorRingN(toIntExact(index) - 1));
}
Aggregations