Search in sources :

Example 6 with Description

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();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryUtils.createJtsEmptyLineString(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyLineString) GeometryUtils.createJtsLineString(com.facebook.presto.geospatial.GeometryUtils.createJtsLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) OGCLineString(com.esri.core.geometry.ogc.OGCLineString) LineString(org.locationtech.jts.geom.LineString) GeometryUtils.createJtsEmptyPolygon(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPolygon) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 7 with Description

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);
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 8 with Description

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();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryType(com.facebook.presto.geospatial.GeometryType) LengthIndexedLine(org.locationtech.jts.linearref.LengthIndexedLine) PrestoException(com.facebook.presto.spi.PrestoException) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 9 with Description

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();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCLineString(com.esri.core.geometry.ogc.OGCLineString) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 10 with Description

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));
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryUtils.createJtsEmptyPolygon(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPolygon) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

Description (com.facebook.presto.spi.function.Description)105 SqlType (com.facebook.presto.spi.function.SqlType)103 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)101 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)41 SqlNullable (com.facebook.presto.spi.function.SqlNullable)37 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)20 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)20 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)20 Geometry (org.locationtech.jts.geom.Geometry)20 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)19 PrestoException (com.facebook.presto.spi.PrestoException)18 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)15 Slice (io.airlift.slice.Slice)15 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)14 Constraint (com.facebook.presto.type.Constraint)14 DecimalOperators.modulusScalarFunction (com.facebook.presto.type.DecimalOperators.modulusScalarFunction)13 Point (com.esri.core.geometry.Point)10 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)7 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)7 Envelope (com.esri.core.geometry.Envelope)6