Search in sources :

Example 26 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry 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 27 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class GeoFunctions method geomFromBinary.

private static OGCGeometry geomFromBinary(Slice input) {
    requireNonNull(input, "input is null");
    OGCGeometry geometry;
    try {
        geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
    } catch (IllegalArgumentException | IndexOutOfBoundsException e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
    }
    geometry.setSpatialReference(null);
    return geometry;
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) PrestoException(com.facebook.presto.spi.PrestoException)

Example 28 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class GeoFunctions method stDifference.

@Description("Returns the Geometry value that represents the point set difference of two geometries")
@ScalarFunction("ST_Difference")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stDifference(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return EsriGeometrySerde.serialize(leftGeometry.difference(rightGeometry));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 29 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class PagesSpatialIndexSupplier method buildRTree.

private static Flatbush<GeometryWithPosition> buildRTree(AdaptiveLongBigArray addresses, int positionCount, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, LocalMemoryContext localUserMemoryContext) {
    Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate);
    ObjectArrayList<GeometryWithPosition> geometries = new ObjectArrayList<>();
    long recordedSizeInBytes = localUserMemoryContext.getBytes();
    long addedSizeInBytes = 0;
    for (int position = 0; position < positionCount; position++) {
        long pageAddress = addresses.get(position);
        int blockIndex = decodeSliceIndex(pageAddress);
        int blockPosition = decodePosition(pageAddress);
        Block block = channels.get(geometryChannel).get(blockIndex);
        // TODO Consider pushing is-null and is-empty checks into a filter below the join
        if (block.isNull(blockPosition)) {
            continue;
        }
        Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition));
        OGCGeometry ogcGeometry = deserialize(slice);
        verify(ogcGeometry != null);
        if (ogcGeometry.isEmpty()) {
            continue;
        }
        double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0);
        if (radius < 0) {
            continue;
        }
        if (!radiusChannel.isPresent()) {
            // If radiusChannel is supplied, this is a distance query, for which our acceleration won't help.
            accelerateGeometry(ogcGeometry, relateOperator);
        }
        int partition = -1;
        if (partitionChannel.isPresent()) {
            Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex);
            partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition));
        }
        GeometryWithPosition geometryWithPosition = new GeometryWithPosition(ogcGeometry, partition, position, radius);
        geometries.add(geometryWithPosition);
        addedSizeInBytes += geometryWithPosition.getEstimatedSizeInBytes();
        if (addedSizeInBytes >= MEMORY_USAGE_UPDATE_INCREMENT_BYTES) {
            localUserMemoryContext.setBytes(recordedSizeInBytes + addedSizeInBytes);
            recordedSizeInBytes += addedSizeInBytes;
            addedSizeInBytes = 0;
        }
    }
    return new Flatbush<>(geometries.toArray(new GeometryWithPosition[] {}));
}
Also used : Operator(com.esri.core.geometry.Operator) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Slice(io.airlift.slice.Slice) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) Supplier(java.util.function.Supplier) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray) Math.toIntExact(java.lang.Math.toIntExact) SyntheticAddress.decodePosition(com.facebook.presto.operator.SyntheticAddress.decodePosition) Type(com.facebook.presto.common.type.Type) Operator(com.esri.core.geometry.Operator) OperatorFactoryLocal(com.esri.core.geometry.OperatorFactoryLocal) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Session(com.facebook.presto.Session) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush) Rectangle(com.facebook.presto.geospatial.Rectangle) DataSize(io.airlift.units.DataSize) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) EsriGeometrySerde.deserialize(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SyntheticAddress.decodeSliceIndex(com.facebook.presto.operator.SyntheticAddress.decodeSliceIndex) GeometryUtils.accelerateGeometry(com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry) Optional(java.util.Optional) EMPTY_INDEX(com.facebook.presto.operator.PagesSpatialIndex.EMPTY_INDEX) Block(com.facebook.presto.common.block.Block) BYTE(io.airlift.units.DataSize.Unit.BYTE) SpatialPredicate(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialPredicate) GeometryWithPosition(com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) GeometryWithPosition(com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition) Slice(io.airlift.slice.Slice) Block(com.facebook.presto.common.block.Block) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush)

Example 30 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class GeometryUtils method accelerateGeometry.

public static void accelerateGeometry(OGCGeometry ogcGeometry, Operator relateOperator, Geometry.GeometryAccelerationDegree accelerationDegree) {
    // Recurse into GeometryCollections
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    while (true) {
        Geometry esriGeometry = cursor.next();
        if (esriGeometry == null) {
            break;
        }
        relateOperator.accelerateGeometry(esriGeometry, null, accelerationDegree);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) Geometry(com.esri.core.geometry.Geometry) GeometryCursor(com.esri.core.geometry.GeometryCursor)

Aggregations

OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)66 SqlType (com.facebook.presto.spi.function.SqlType)22 Description (com.facebook.presto.spi.function.Description)21 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)21 SqlNullable (com.facebook.presto.spi.function.SqlNullable)14 Point (com.esri.core.geometry.Point)12 ExecException (org.apache.pig.backend.executionengine.ExecException)12 DataByteArray (org.apache.pig.data.DataByteArray)8 Geometry (com.esri.core.geometry.Geometry)7 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)7 Envelope (com.esri.core.geometry.Envelope)6 OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)6 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)6 ArrayList (java.util.ArrayList)6 Slice (io.airlift.slice.Slice)5 GeometryCursor (com.esri.core.geometry.GeometryCursor)4 MultiPoint (com.esri.core.geometry.MultiPoint)4 OGCMultiPoint (com.esri.core.geometry.ogc.OGCMultiPoint)4 Tuple (org.apache.pig.data.Tuple)4 Page (com.facebook.presto.common.Page)3