Search in sources :

Example 6 with Rectangle

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

the class SpatialPartitioningInternalAggregateFunction method output.

@OutputFunction(StandardTypes.VARCHAR)
public static void output(SpatialPartitioningState state, BlockBuilder out) {
    if (state.getCount() == 0) {
        out.appendNull();
        return;
    }
    List<Rectangle> samples = state.getSamples();
    int partitionCount = state.getPartitionCount();
    int maxItemsPerNode = (samples.size() + partitionCount - 1) / partitionCount;
    Rectangle envelope = state.getExtent();
    // Add a small buffer on the right and upper sides
    Rectangle paddedExtent = new Rectangle(envelope.getXMin(), envelope.getYMin(), Math.nextUp(envelope.getXMax()), Math.nextUp(envelope.getYMax()));
    VARCHAR.writeString(out, KdbTreeUtils.toJson(buildKdbTree(maxItemsPerNode, paddedExtent, samples)));
}
Also used : Rectangle(io.trino.geospatial.Rectangle) OutputFunction(io.trino.spi.function.OutputFunction)

Example 7 with Rectangle

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

the class PagesRTreeIndex method testReferencePoint.

private boolean testReferencePoint(Envelope probeEnvelope, OGCGeometry buildGeometry, int partition) {
    Envelope buildEnvelope = getEnvelope(buildGeometry);
    Envelope intersection = buildEnvelope.intersection(probeEnvelope);
    if (intersection.isNull()) {
        return false;
    }
    Rectangle extent = partitions.get(partition);
    double x = intersection.getMinX();
    double y = intersection.getMinY();
    return x >= extent.getXMin() && x < extent.getXMax() && y >= extent.getYMin() && y < extent.getYMax();
}
Also used : Rectangle(io.trino.geospatial.Rectangle) Envelope(org.locationtech.jts.geom.Envelope)

Example 8 with Rectangle

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

the class GeoFunctions method spatialPartitions.

@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a geometry representing a set of points within specified distance from the input geometry")
@SqlType("array(integer)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(GEOMETRY_TYPE_NAME) Slice geometry, @SqlType(DOUBLE) double distance) {
    if (isNaN(distance)) {
        throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN");
    }
    if (isInfinite(distance)) {
        throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "distance is infinite");
    }
    if (distance < 0) {
        throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "distance is negative");
    }
    Envelope envelope = deserializeEnvelope(geometry);
    if (envelope.isEmpty()) {
        return null;
    }
    Rectangle expandedEnvelope2D = new Rectangle(envelope.getXMin() - distance, envelope.getYMin() - distance, envelope.getXMax() + distance, envelope.getYMax() + distance);
    return spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
Also used : Rectangle(io.trino.geospatial.Rectangle) TrinoException(io.trino.spi.TrinoException) GeometrySerde.deserializeEnvelope(io.trino.geospatial.serde.GeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Aggregations

Rectangle (io.trino.geospatial.Rectangle)8 Envelope (com.esri.core.geometry.Envelope)3 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)2 GeometrySerde.deserializeEnvelope (io.trino.geospatial.serde.GeometrySerde.deserializeEnvelope)2 BlockBuilder (io.trino.spi.block.BlockBuilder)2 MultiPoint (com.esri.core.geometry.MultiPoint)1 Point (com.esri.core.geometry.Point)1 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)1 VerifyException (com.google.common.base.VerifyException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KdbTree (io.trino.geospatial.KdbTree)1 Node (io.trino.geospatial.KdbTree.Node)1 AggregationTestUtils.createGroupByIdBlock (io.trino.operator.aggregation.AggregationTestUtils.createGroupByIdBlock)1 AggregationTestUtils.getFinalBlock (io.trino.operator.aggregation.AggregationTestUtils.getFinalBlock)1 Aggregator (io.trino.operator.aggregation.Aggregator)1 AggregatorFactory (io.trino.operator.aggregation.AggregatorFactory)1 GroupedAggregator (io.trino.operator.aggregation.GroupedAggregator)1 TestingAggregationFunction (io.trino.operator.aggregation.TestingAggregationFunction)1 Page (io.trino.spi.Page)1