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);
}
Aggregations