Search in sources :

Example 21 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class TestSpatialPartitioningInternalAggregation method test.

@Test(dataProvider = "partitionCount")
public void test(int partitionCount) {
    InternalAggregationFunction function = getFunction();
    List<OGCGeometry> geometries = makeGeometries();
    Block geometryBlock = makeGeometryBlock(geometries);
    Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size());
    String expectedValue = getSpatialPartitioning(geometries, partitionCount);
    AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1), Optional.empty());
    Page page = new Page(geometryBlock, partitionCountBlock);
    Accumulator accumulator = accumulatorFactory.createAccumulator(UpdateMemory.NOOP);
    accumulator.addInput(page);
    String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator));
    assertEquals(aggregation, expectedValue);
    GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(UpdateMemory.NOOP);
    groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page);
    String groupValue = (String) getGroupValue(groupedAggregation, 0);
    assertEquals(groupValue, expectedValue);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GroupedAccumulator(com.facebook.presto.operator.aggregation.GroupedAccumulator) Accumulator(com.facebook.presto.operator.aggregation.Accumulator) AccumulatorFactory(com.facebook.presto.operator.aggregation.AccumulatorFactory) AggregationTestUtils.createGroupByIdBlock(com.facebook.presto.operator.aggregation.AggregationTestUtils.createGroupByIdBlock) AggregationTestUtils.getFinalBlock(com.facebook.presto.operator.aggregation.AggregationTestUtils.getFinalBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) GroupedAccumulator(com.facebook.presto.operator.aggregation.GroupedAccumulator) Test(org.testng.annotations.Test)

Example 22 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class TestBingTile method assertTileCovering.

private void assertTileCovering(String wkt, int zoom, List<String> quadkeys) {
    OGCGeometry geometry = OGCGeometry.fromText(wkt);
    List<String> actual = findDissolvedTileCovering(geometry, zoom).stream().map(BingTile::toQuadKey).sorted().collect(toImmutableList());
    List<String> expected = ImmutableList.sortedCopyOf(quadkeys);
    assertEquals(actual, expected, format("Actual:\n%s\nExpected:\n%s", actual, expected));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry)

Example 23 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class TestGeometrySerialization method testEsriSerialization.

private static void testEsriSerialization(String wkt) {
    OGCGeometry expected = OGCGeometry.fromText(wkt);
    OGCGeometry actual = deserialize(serialize(expected));
    assertGeometryEquals(actual, expected);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry)

Example 24 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class TestGeometrySerialization method tryDeserializeJtsFromEsri.

private static void tryDeserializeJtsFromEsri(String wkt) {
    OGCGeometry esriGeometry = OGCGeometry.fromText(wkt);
    JtsGeometrySerde.deserialize(EsriGeometrySerde.serialize(esriGeometry));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry)

Example 25 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class BingTileFunctions method geometryToBingTiles.

@Description("Given a geometry and a zoom level, returns the minimum set of Bing tiles of that zoom level that fully covers that geometry")
@ScalarFunction("geometry_to_bing_tiles")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block geometryToBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.INTEGER) long zoomLevelInput) {
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return EMPTY_TILE_ARRAY;
    }
    int zoomLevel = toIntExact(zoomLevelInput);
    GeometrySerializationType type = deserializeType(input);
    List<BingTile> covering;
    if (type == GeometrySerializationType.POINT || type == GeometrySerializationType.ENVELOPE) {
        covering = findMinimalTileCovering(envelope, zoomLevel);
    } else {
        OGCGeometry ogcGeometry = deserialize(input);
        if (isPointOrRectangle(ogcGeometry, envelope)) {
            covering = findMinimalTileCovering(envelope, zoomLevel);
        } else {
            covering = findMinimalTileCovering(ogcGeometry, zoomLevel);
        }
    }
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, covering.size());
    for (BingTile tile : covering) {
        BIGINT.writeLong(blockBuilder, tile.encode());
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometrySerializationType(com.facebook.presto.geospatial.serde.GeometrySerializationType) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) BingTileUtils.tileToEnvelope(com.facebook.presto.plugin.geospatial.BingTileUtils.tileToEnvelope) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.disjoint(com.facebook.presto.geospatial.GeometryUtils.disjoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)66 SqlType (com.facebook.presto.spi.function.SqlType)22 Description (com.facebook.presto.spi.function.Description)21 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)21 SqlNullable (com.facebook.presto.spi.function.SqlNullable)14 Point (com.esri.core.geometry.Point)12 ExecException (org.apache.pig.backend.executionengine.ExecException)12 DataByteArray (org.apache.pig.data.DataByteArray)8 Geometry (com.esri.core.geometry.Geometry)7 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)7 Envelope (com.esri.core.geometry.Envelope)6 OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)6 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)6 ArrayList (java.util.ArrayList)6 Slice (io.airlift.slice.Slice)5 GeometryCursor (com.esri.core.geometry.GeometryCursor)4 MultiPoint (com.esri.core.geometry.MultiPoint)4 OGCMultiPoint (com.esri.core.geometry.ogc.OGCMultiPoint)4 Tuple (org.apache.pig.data.Tuple)4 Page (com.facebook.presto.common.Page)3