Search in sources :

Example 6 with GeometryType

use of io.prestosql.geospatial.GeometryType in project hetu-core by openlookeng.

the class GeoFunctions method stGeometryN.

@SqlNullable
@Description("Returns the geometry element at the specified index (indices started with 1)")
@ScalarFunction("ST_GeometryN")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stGeometryN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) {
    OGCGeometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (!type.isMultitype()) {
        if (index == 1) {
            return input;
        }
        return null;
    }
    OGCGeometryCollection geometryCollection = ((OGCGeometryCollection) geometry);
    if (index < 1 || index > geometryCollection.numGeometries()) {
        return null;
    }
    OGCGeometry ogcGeometry = geometryCollection.geometryN((int) index - 1);
    return serialize(ogcGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometryType(io.prestosql.geospatial.GeometryType) OGCGeometryCollection(com.esri.core.geometry.ogc.OGCGeometryCollection) 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

OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)6 GeometryType (io.prestosql.geospatial.GeometryType)6 Description (io.prestosql.spi.function.Description)6 ScalarFunction (io.prestosql.spi.function.ScalarFunction)6 SqlType (io.prestosql.spi.function.SqlType)6 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)3 SqlNullable (io.prestosql.spi.function.SqlNullable)3 MultiPoint (com.esri.core.geometry.MultiPoint)2 MultiVertexGeometry (com.esri.core.geometry.MultiVertexGeometry)2 Point (com.esri.core.geometry.Point)2 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)2 PrestoException (io.prestosql.spi.PrestoException)2 GeometryCursor (com.esri.core.geometry.GeometryCursor)1 ListeningGeometryCursor (com.esri.core.geometry.ListeningGeometryCursor)1 Polygon (com.esri.core.geometry.Polygon)1 Polyline (com.esri.core.geometry.Polyline)1 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)1 OGCMultiPolygon (com.esri.core.geometry.ogc.OGCMultiPolygon)1 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)1 BlockBuilder (io.prestosql.spi.block.BlockBuilder)1