Search in sources :

Example 16 with SqlNullable

use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.

the class GeoFunctions method stIntersects.

@SqlNullable
@Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)")
@ScalarFunction("ST_Intersects")
@SqlType(BOOLEAN)
public static Boolean stIntersects(@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.intersects(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) SqlNullable(io.prestosql.spi.function.SqlNullable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Example 17 with SqlNullable

use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.

the class GeoFunctions method stMultiPoint.

@SqlNullable
@Description("Returns a multi-point geometry formed from input points")
@ScalarFunction("ST_MultiPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) {
    MultiPoint multipoint = new MultiPoint();
    for (int i = 0; i < input.getPositionCount(); i++) {
        if (input.isNull(i)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: null at index %s", i + 1));
        }
        Slice slice = GEOMETRY.getSlice(input, i);
        OGCGeometry geometry = deserialize(slice);
        if (!(geometry instanceof OGCPoint)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: geometry is not a point: %s at index %s", geometry.geometryType(), i + 1));
        }
        OGCPoint point = (OGCPoint) geometry;
        if (point.isEmpty()) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: empty point at index %s", i + 1));
        }
        multipoint.add(point.X(), point.Y());
    }
    if (multipoint.getPointCount() == 0) {
        return null;
    }
    return serialize(createFromEsriGeometry(multipoint, null, true));
}
Also used : MultiPoint(com.esri.core.geometry.MultiPoint) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) PrestoException(io.prestosql.spi.PrestoException) MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) SqlNullable(io.prestosql.spi.function.SqlNullable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Example 18 with SqlNullable

use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.

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) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_InteriorRingN", geometry, EnumSet.of(POLYGON));
    OGCPolygon polygon = (OGCPolygon) geometry;
    if (index < 1 || index > polygon.numInteriorRing()) {
        return null;
    }
    OGCGeometry interiorRing = polygon.interiorRingN(toIntExact(index) - 1);
    return serialize(interiorRing);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) SqlNullable(io.prestosql.spi.function.SqlNullable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Example 19 with SqlNullable

use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.

the class GeoFunctions method spatialPartitions.

@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a geometry representing a set of points within specified distance from the input geometry")
@SqlType("array(integer)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(GEOMETRY_TYPE_NAME) Slice geometry, @SqlType(DOUBLE) double distance) {
    if (isNaN(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN");
    }
    if (isInfinite(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is infinite");
    }
    if (distance < 0) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative");
    }
    Envelope envelope = deserializeEnvelope(geometry);
    if (envelope == null) {
        return null;
    }
    Rectangle expandedEnvelope2D = new Rectangle(envelope.getXMin() - distance, envelope.getYMin() - distance, envelope.getXMax() + distance, envelope.getYMax() + distance);
    return spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
Also used : Rectangle(io.prestosql.geospatial.Rectangle) PrestoException(io.prestosql.spi.PrestoException) GeometrySerde.deserializeEnvelope(io.prestosql.geospatial.serde.GeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) SqlNullable(io.prestosql.spi.function.SqlNullable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Example 20 with SqlNullable

use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.

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) {
    OGCGeometry geometry = deserialize(input);
    validateType("ST_IsClosed", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING));
    MultiPath lines = (MultiPath) geometry.getEsriGeometry();
    int pathCount = lines.getPathCount();
    for (int i = 0; i < pathCount; i++) {
        Point start = lines.getPoint(lines.getPathStart(i));
        Point end = lines.getPoint(lines.getPathEnd(i) - 1);
        if (!end.equals(start)) {
            return false;
        }
    }
    return true;
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiPath(com.esri.core.geometry.MultiPath) MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) SqlNullable(io.prestosql.spi.function.SqlNullable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Aggregations

SqlNullable (io.prestosql.spi.function.SqlNullable)52 SqlType (io.prestosql.spi.function.SqlType)52 ScalarFunction (io.prestosql.spi.function.ScalarFunction)40 Description (io.prestosql.spi.function.Description)34 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)28 JsonParser (com.fasterxml.jackson.core.JsonParser)14 PrestoException (io.prestosql.spi.PrestoException)14 JsonUtil.createJsonParser (io.prestosql.util.JsonUtil.createJsonParser)14 IOException (java.io.IOException)14 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)11 MultiPoint (com.esri.core.geometry.MultiPoint)9 Point (com.esri.core.geometry.Point)9 BlockBuilder (io.prestosql.spi.block.BlockBuilder)8 ScalarOperator (io.prestosql.spi.function.ScalarOperator)8 JsonCastException (io.prestosql.util.JsonCastException)8 LiteralParameters (io.prestosql.spi.function.LiteralParameters)7 JsonToken (com.fasterxml.jackson.core.JsonToken)6 Slice (io.airlift.slice.Slice)6 MultiPath (com.esri.core.geometry.MultiPath)4 Block (io.prestosql.spi.block.Block)4