use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class GeoFunctions method stGeometries.
@SqlNullable
@Description("Returns an array of geometries in the specified collection")
@ScalarFunction("ST_Geometries")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
if (geometry.isEmpty()) {
return null;
}
GeometryType type = GeometryType.getForJtsGeometryType(geometry.getGeometryType());
if (!type.isMultitype()) {
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1);
GEOMETRY.writeSlice(blockBuilder, serialize(geometry));
return blockBuilder.build();
}
GeometryCollection collection = (GeometryCollection) geometry;
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.getNumGeometries());
for (int i = 0; i < collection.getNumGeometries(); i++) {
GEOMETRY.writeSlice(blockBuilder, serialize(collection.getGeometryN(i)));
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class GeoFunctions method flattenGeometryCollections.
@Description("Recursively flattens GeometryCollections")
@ScalarFunction("flatten_geometry_collections")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block flattenGeometryCollections(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
List<OGCGeometry> components = Streams.stream(flattenCollection(geometry)).collect(toImmutableList());
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, components.size());
for (OGCGeometry component : components) {
GEOMETRY.writeSlice(blockBuilder, EsriGeometrySerde.serialize(component));
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class GeoFunctions method stInteriorRings.
@SqlNullable
@Description("Returns an array of interior rings of a polygon")
@ScalarFunction("ST_InteriorRings")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
validateType("ST_InteriorRings", geometry, EnumSet.of(POLYGON));
if (geometry.isEmpty()) {
return null;
}
org.locationtech.jts.geom.Polygon polygon = (org.locationtech.jts.geom.Polygon) geometry;
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, polygon.getNumInteriorRing());
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
GEOMETRY.writeSlice(blockBuilder, serialize((LineString) polygon.getInteriorRingN(i)));
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class GeoFunctions method stEnvelopeAsPts.
@SqlNullable
@Description("Returns the lower left and upper right corners of bounding rectangular polygon of a Geometry")
@ScalarFunction("ST_EnvelopeAsPts")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stEnvelopeAsPts(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Envelope envelope = deserializeEnvelope(input);
if (envelope.isEmpty()) {
return null;
}
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
org.locationtech.jts.geom.Point lowerLeftCorner = createJtsPoint(envelope.getXMin(), envelope.getYMin());
org.locationtech.jts.geom.Point upperRightCorner = createJtsPoint(envelope.getXMax(), envelope.getYMax());
GEOMETRY.writeSlice(blockBuilder, serialize(lowerLeftCorner));
GEOMETRY.writeSlice(blockBuilder, serialize(upperRightCorner));
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class BingTileFunctions method geometryToBingTiles.
@Description("Given a geometry and a zoom level, returns the minimum set of Bing tiles of that zoom level that fully covers that geometry")
@ScalarFunction("geometry_to_bing_tiles")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block geometryToBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.INTEGER) long zoomLevelInput) {
Envelope envelope = deserializeEnvelope(input);
if (envelope.isEmpty()) {
return EMPTY_TILE_ARRAY;
}
int zoomLevel = toIntExact(zoomLevelInput);
GeometrySerializationType type = deserializeType(input);
List<BingTile> covering;
if (type == GeometrySerializationType.POINT || type == GeometrySerializationType.ENVELOPE) {
covering = findMinimalTileCovering(envelope, zoomLevel);
} else {
OGCGeometry ogcGeometry = deserialize(input);
if (isPointOrRectangle(ogcGeometry, envelope)) {
covering = findMinimalTileCovering(envelope, zoomLevel);
} else {
covering = findMinimalTileCovering(ogcGeometry, zoomLevel);
}
}
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, covering.size());
for (BingTile tile : covering) {
BIGINT.writeLong(blockBuilder, tile.encode());
}
return blockBuilder.build();
}
Aggregations