Search in sources :

Example 11 with Rectangle

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);
    }
}
Also used : POSITIVE_INFINITY(java.lang.Double.POSITIVE_INFINITY) DataProvider(org.testng.annotations.DataProvider) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Random(java.util.Random) Rectangle(com.facebook.presto.geospatial.Rectangle) NEGATIVE_INFINITY(java.lang.Double.NEGATIVE_INFINITY) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) ENVELOPE_SIZE(com.facebook.presto.geospatial.rtree.Flatbush.ENVELOPE_SIZE) GeometryUtils(com.facebook.presto.geospatial.GeometryUtils) RtreeTestUtils.makeRectangles(com.facebook.presto.geospatial.rtree.RtreeTestUtils.makeRectangles) Point(com.esri.core.geometry.Point) Comparator(java.util.Comparator) Random(java.util.Random) Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Example 12 with Rectangle

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)));
}
Also used : Arrays(java.util.Arrays) Math.min(java.lang.Math.min) Rectangle(com.facebook.presto.geospatial.Rectangle) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ClassLayout(org.openjdk.jol.info.ClassLayout) SizeOf.sizeOf(io.airlift.slice.SizeOf.sizeOf) Objects.requireNonNull(java.util.Objects.requireNonNull) Math.max(java.lang.Math.max) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DoubleBigArray(com.facebook.presto.common.array.DoubleBigArray) Comparator(java.util.Comparator) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Rectangle(com.facebook.presto.geospatial.Rectangle)

Example 13 with Rectangle

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);
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Example 14 with Rectangle

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);
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) Test(org.testng.annotations.Test)

Example 15 with Rectangle

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();
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

Rectangle (com.facebook.presto.geospatial.Rectangle)19 Test (org.testng.annotations.Test)11 Envelope (com.esri.core.geometry.Envelope)4 Point (com.esri.core.geometry.Point)3 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)3 EsriGeometrySerde.deserializeEnvelope (com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope)3 List (java.util.List)3 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)2 GeometryUtils (com.facebook.presto.geospatial.GeometryUtils)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Description (com.facebook.presto.spi.function.Description)2 ImmutableList (com.google.common.collect.ImmutableList)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 ClassLayout (org.openjdk.jol.info.ClassLayout)2 Session (com.facebook.presto.Session)1 Page (com.facebook.presto.common.Page)1 PageBuilder (com.facebook.presto.common.PageBuilder)1