Search in sources :

Example 6 with Rectangle

use of io.prestosql.geospatial.Rectangle in project hetu-core by openlookeng.

the class SpatialPartitioningInternalAggregateFunction method input.

@InputFunction
public static void input(SpatialPartitioningState state, @SqlType(GEOMETRY_TYPE_NAME) Slice slice, @SqlType(INTEGER) long partitionCount) {
    Envelope envelope = deserializeEnvelope(slice);
    if (envelope == null) {
        return;
    }
    Rectangle extent = new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax());
    if (state.getCount() == 0) {
        state.setPartitionCount(toIntExact(partitionCount));
        state.setExtent(extent);
        state.setSamples(new ArrayList<>());
    } else {
        state.setExtent(state.getExtent().merge(extent));
    }
    // use reservoir sampling
    List<Rectangle> samples = state.getSamples();
    if (samples.size() <= MAX_SAMPLE_COUNT) {
        samples.add(extent);
    } else {
        long sampleIndex = ThreadLocalRandom.current().nextLong(state.getCount());
        if (sampleIndex < MAX_SAMPLE_COUNT) {
            samples.set(toIntExact(sampleIndex), extent);
        }
    }
    state.setCount(state.getCount() + 1);
}
Also used : Rectangle(io.prestosql.geospatial.Rectangle) Envelope(com.esri.core.geometry.Envelope) GeometrySerde.deserializeEnvelope(io.prestosql.geospatial.serde.GeometrySerde.deserializeEnvelope) InputFunction(io.prestosql.spi.function.InputFunction)

Example 7 with Rectangle

use of io.prestosql.geospatial.Rectangle in project hetu-core by openlookeng.

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.prestosql.geospatial.Rectangle) Envelope(org.locationtech.jts.geom.Envelope)

Aggregations

Rectangle (io.prestosql.geospatial.Rectangle)7 Envelope (com.esri.core.geometry.Envelope)3 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)2 GeometrySerde.deserializeEnvelope (io.prestosql.geospatial.serde.GeometrySerde.deserializeEnvelope)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 Accumulator (io.prestosql.operator.aggregation.Accumulator)1 AccumulatorFactory (io.prestosql.operator.aggregation.AccumulatorFactory)1 AggregationTestUtils.createGroupByIdBlock (io.prestosql.operator.aggregation.AggregationTestUtils.createGroupByIdBlock)1 AggregationTestUtils.getFinalBlock (io.prestosql.operator.aggregation.AggregationTestUtils.getFinalBlock)1 GroupedAccumulator (io.prestosql.operator.aggregation.GroupedAccumulator)1 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)1 Page (io.prestosql.spi.Page)1 PrestoException (io.prestosql.spi.PrestoException)1 Block (io.prestosql.spi.block.Block)1 BlockBuilder (io.prestosql.spi.block.BlockBuilder)1