Search in sources :

Example 6 with GeometryType

use of io.trino.geospatial.GeometryType in project trino by trinodb.

the class EncodedPolylineFunctions method toEncodedPolyline.

@Description("Encodes a linestring or multipoint geometry to a polyline")
@ScalarFunction("to_encoded_polyline")
@SqlType(StandardTypes.VARCHAR)
public static Slice toEncodedPolyline(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    validateType("encode_polyline", geometry, EnumSet.of(LINE_STRING, MULTI_POINT));
    GeometryType geometryType = GeometryType.getForEsriGeometryType(geometry.geometryType());
    switch(geometryType) {
        case LINE_STRING:
        case MULTI_POINT:
            return encodePolyline((MultiVertexGeometry) geometry.getEsriGeometry());
        default:
            throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "Unexpected geometry type: " + geometryType);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometryType(io.trino.geospatial.GeometryType) TrinoException(io.trino.spi.TrinoException) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 7 with GeometryType

use of io.trino.geospatial.GeometryType in project trino by trinodb.

the class GeoFunctions method stNumGeometries.

@Description("Returns the cardinality of the geometry collection")
@ScalarFunction("ST_NumGeometries")
@SqlType(INTEGER)
public static long stNumGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return 0;
    }
    GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (!type.isMultitype()) {
        return 1;
    }
    return ((OGCGeometryCollection) geometry).numGeometries();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometryType(io.trino.geospatial.GeometryType) OGCGeometryCollection(com.esri.core.geometry.ogc.OGCGeometryCollection) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Aggregations

OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)7 GeometryType (io.trino.geospatial.GeometryType)7 Description (io.trino.spi.function.Description)7 ScalarFunction (io.trino.spi.function.ScalarFunction)7 SqlType (io.trino.spi.function.SqlType)7 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)3 TrinoException (io.trino.spi.TrinoException)3 SqlNullable (io.trino.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 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 GeometryUtils.jsonFromJtsGeometry (io.trino.geospatial.GeometryUtils.jsonFromJtsGeometry)1