use of com.facebook.presto.spi.function.SqlNullable in project presto by prestodb.
the class GeoFunctions method stGeometries.
@SqlNullable
@Description("Returns an array of geometries in the specified collection")
@ScalarFunction("ST_Geometries")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
if (geometry.isEmpty()) {
return null;
}
GeometryType type = GeometryType.getForJtsGeometryType(geometry.getGeometryType());
if (!type.isMultitype()) {
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1);
GEOMETRY.writeSlice(blockBuilder, serialize(geometry));
return blockBuilder.build();
}
GeometryCollection collection = (GeometryCollection) geometry;
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.getNumGeometries());
for (int i = 0; i < collection.getNumGeometries(); i++) {
GEOMETRY.writeSlice(blockBuilder, serialize(collection.getGeometryN(i)));
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.function.SqlNullable 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.SqlNullable 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.SqlNullable 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.SqlNullable 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