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);
}
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();
}
Aggregations