Search in sources :

Example 26 with ScalarFunction

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

the class GeoFunctions method stDifference.

@Description("Returns the Geometry value that represents the point set difference of two geometries")
@ScalarFunction("ST_Difference")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stDifference(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return serialize(leftGeometry.difference(rightGeometry));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Example 27 with ScalarFunction

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

the class GeoFunctions method stDisjoint.

@SqlNullable
@Description("Returns TRUE if the Geometries do not spatially intersect - if they do not share any space together")
@ScalarFunction("ST_Disjoint")
@SqlType(BOOLEAN)
public static Boolean stDisjoint(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::intersect)) {
        return true;
    }
    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.disjoint(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 28 with ScalarFunction

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

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 = 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(io.prestosql.spi.function.SqlNullable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) Description(io.prestosql.spi.function.Description) SqlType(io.prestosql.spi.function.SqlType)

Example 29 with ScalarFunction

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

the class GeoFunctions method stCrosses.

@SqlNullable
@Description("Returns TRUE if the supplied geometries have some, but not all, interior points in common")
@ScalarFunction("ST_Crosses")
@SqlType(BOOLEAN)
public static Boolean stCrosses(@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.crosses(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 30 with ScalarFunction

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

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 = JtsGeometrySerde.deserialize(lineSlice);
    Geometry point = JtsGeometrySerde.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 : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) GeometryType(io.prestosql.geospatial.GeometryType) LengthIndexedLine(org.locationtech.jts.linearref.LengthIndexedLine) PrestoException(io.prestosql.spi.PrestoException) 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

ScalarFunction (io.prestosql.spi.function.ScalarFunction)97 SqlType (io.prestosql.spi.function.SqlType)96 Description (io.prestosql.spi.function.Description)76 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)40 SqlNullable (io.prestosql.spi.function.SqlNullable)40 LiteralParameters (io.prestosql.spi.function.LiteralParameters)20 Slice (io.airlift.slice.Slice)18 BlockBuilder (io.prestosql.spi.block.BlockBuilder)17 Constraint (io.prestosql.type.Constraint)16 Point (com.esri.core.geometry.Point)14 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)14 MultiPoint (com.esri.core.geometry.MultiPoint)12 PrestoException (io.prestosql.spi.PrestoException)12 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)8 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)8 JsonParser (com.fasterxml.jackson.core.JsonParser)7 JsonUtil.createJsonParser (io.prestosql.util.JsonUtil.createJsonParser)7 IOException (java.io.IOException)7 JsonToken (com.fasterxml.jackson.core.JsonToken)6 GeometryType (io.prestosql.geospatial.GeometryType)6