use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class TestFlatbush method testRectangleCollection.
@Test(dataProvider = "rectangle-counts")
public void testRectangleCollection(int numBuildRectangles, int numProbeRectangles, int seed) {
Random random = new Random(seed);
List<Rectangle> buildRectangles = makeRectangles(random, numBuildRectangles);
List<Rectangle> probeRectangles = makeRectangles(random, numProbeRectangles);
Flatbush<Rectangle> rtree = new Flatbush<>(buildRectangles.toArray(new Rectangle[] {}));
for (Rectangle query : probeRectangles) {
List<Rectangle> actual = findIntersections(rtree, query);
List<Rectangle> expected = buildRectangles.stream().filter(rect -> rect.intersects(query)).collect(toList());
assertEqualsSorted(actual, expected, RECTANGLE_COMPARATOR);
}
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class Flatbush method sortByHilbertIndex.
/*
* Sorts items in-place by the Hilbert index of the envelope center.
*/
private void sortByHilbertIndex(T[] items) {
if (items == null || items.length < 2) {
return;
}
Rectangle totalExtent = items[0].getExtent();
for (int i = 1; i < items.length; i++) {
totalExtent = totalExtent.merge(items[i].getExtent());
}
HilbertIndex hilbert = new HilbertIndex(totalExtent);
Arrays.parallelSort(items, Comparator.comparing(item -> hilbert.indexOf((item.getExtent().getXMin() + item.getExtent().getXMax()) / 2, (item.getExtent().getYMin() + item.getExtent().getYMax()) / 2)));
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class TestHilbertIndex method testDegenerateHorizontalRectangle.
@Test
public void testDegenerateHorizontalRectangle() {
HilbertIndex hilbert = new HilbertIndex(new Rectangle(0, 0, 4, 0));
assertEquals(hilbert.indexOf(0., 0.), 0);
assertTrue(hilbert.indexOf(1., 0.) < hilbert.indexOf(2., 0.));
assertEquals(hilbert.indexOf(0., 2.), Long.MAX_VALUE);
assertEquals(hilbert.indexOf(2., 2.), Long.MAX_VALUE);
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class TestHilbertIndex method testDegenerateRectangle.
@Test
public void testDegenerateRectangle() {
HilbertIndex hilbert = new HilbertIndex(new Rectangle(0, 0, 0, 0));
assertEquals(hilbert.indexOf(0., 0.), 0);
assertEquals(hilbert.indexOf(2., 2.), Long.MAX_VALUE);
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class GeoFunctions method spatialPartitions.
// Package visible for SphericalGeoFunctions
/*package*/
static Block spatialPartitions(KdbTree kdbTree, Rectangle envelope) {
Map<Integer, Rectangle> partitions = kdbTree.findIntersectingLeaves(envelope);
if (partitions.isEmpty()) {
return EMPTY_ARRAY_OF_INTS;
}
BlockBuilder blockBuilder = IntegerType.INTEGER.createFixedSizeBlockBuilder(partitions.size());
for (int id : partitions.keySet()) {
blockBuilder.writeInt(id);
}
return blockBuilder.build();
}
Aggregations