Search in sources :

Example 21 with Description

use of com.facebook.presto.spi.function.Description 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();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometrySerializationType(com.facebook.presto.geospatial.serde.GeometrySerializationType) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) BingTileUtils.tileToEnvelope(com.facebook.presto.plugin.geospatial.BingTileUtils.tileToEnvelope) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.disjoint(com.facebook.presto.geospatial.GeometryUtils.disjoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 22 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class BingTileFunctions method geometryToDissolvedBingTiles.

@Description("Given a geometry and a maximum zoom level, returns the minimum set of dissolved Bing tiles that fully covers that geometry")
@ScalarFunction("geometry_to_dissolved_bing_tiles")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block geometryToDissolvedBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.INTEGER) long maxZoomLevel) {
    OGCGeometry ogcGeometry = deserialize(input);
    if (ogcGeometry.isEmpty()) {
        return EMPTY_TILE_ARRAY;
    }
    List<BingTile> covering = findDissolvedTileCovering(ogcGeometry, toIntExact(maxZoomLevel));
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, covering.size());
    for (BingTile tile : covering) {
        BIGINT.writeLong(blockBuilder, tile.encode());
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 23 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class BingTileFunctions method bingTilesAround.

@Description("Given a (longitude, latitude) point, returns the surrounding Bing tiles at the specified zoom level")
@ScalarFunction("bing_tiles_around")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block bingTilesAround(@SqlType(StandardTypes.DOUBLE) double latitude, @SqlType(StandardTypes.DOUBLE) double longitude, @SqlType(StandardTypes.INTEGER) long zoomLevel) {
    checkLatitude(latitude, LATITUDE_OUT_OF_RANGE);
    checkLongitude(longitude, LONGITUDE_OUT_OF_RANGE);
    checkZoomLevel(zoomLevel);
    long mapSize = mapSize(toIntExact(zoomLevel));
    long maxTileIndex = (mapSize / TILE_PIXELS) - 1;
    int tileX = longitudeToTileX(longitude, mapSize);
    int tileY = latitudeToTileY(latitude, mapSize);
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 9);
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            int x = tileX + i;
            int y = tileY + j;
            if (x >= 0 && x <= maxTileIndex && y >= 0 && y <= maxTileIndex) {
                BIGINT.writeLong(blockBuilder, BingTile.fromCoordinates(x, y, toIntExact(zoomLevel)).encode());
            }
        }
    }
    return blockBuilder.build();
}
Also used : GeometryUtils.disjoint(com.facebook.presto.geospatial.GeometryUtils.disjoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 24 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class GeoFunctions method geometryNearestPoints.

@SqlNullable
@Description("Return the closest points on the two geometries")
@ScalarFunction("geometry_nearest_points")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block geometryNearestPoints(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    Geometry leftGeometry = deserialize(left);
    Geometry rightGeometry = deserialize(right);
    if (leftGeometry.isEmpty() || rightGeometry.isEmpty()) {
        return null;
    }
    try {
        Coordinate[] nearestCoordinates = DistanceOp.nearestPoints(leftGeometry, rightGeometry);
        BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
        GEOMETRY.writeSlice(blockBuilder, serialize(createJtsPoint(nearestCoordinates[0])));
        GEOMETRY.writeSlice(blockBuilder, serialize(createJtsPoint(nearestCoordinates[1])));
        return blockBuilder.build();
    } catch (TopologyException e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
    }
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) Coordinate(org.locationtech.jts.geom.Coordinate) PrestoException(com.facebook.presto.spi.PrestoException) TopologyException(org.locationtech.jts.geom.TopologyException) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 25 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class GeoFunctions method stNumInteriorRings.

@SqlNullable
@Description("Returns the cardinality of the collection of interior rings of a polygon")
@ScalarFunction("ST_NumInteriorRing")
@SqlType(BIGINT)
public static Long stNumInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_NumInteriorRing", geometry, EnumSet.of(POLYGON));
    if (geometry.isEmpty()) {
        return null;
    }
    return Long.valueOf(((org.locationtech.jts.geom.Polygon) geometry).getNumInteriorRing());
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

Description (com.facebook.presto.spi.function.Description)105 SqlType (com.facebook.presto.spi.function.SqlType)103 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)101 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)41 SqlNullable (com.facebook.presto.spi.function.SqlNullable)37 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)20 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)20 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)20 Geometry (org.locationtech.jts.geom.Geometry)20 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)19 PrestoException (com.facebook.presto.spi.PrestoException)18 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)15 Slice (io.airlift.slice.Slice)15 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)14 Constraint (com.facebook.presto.type.Constraint)14 DecimalOperators.modulusScalarFunction (com.facebook.presto.type.DecimalOperators.modulusScalarFunction)13 Point (com.esri.core.geometry.Point)10 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)7 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)7 Envelope (com.esri.core.geometry.Envelope)6