Search in sources :

Example 6 with Envelope

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

the class TestGeometrySerialization method testEnvelope.

@Test
public void testEnvelope() {
    testEnvelopeSerialization(new Envelope());
    testEnvelopeSerialization(new Envelope(0, 0, 1, 1));
    testEnvelopeSerialization(new Envelope(1, 2, 3, 4));
    testEnvelopeSerialization(new Envelope(10101, -2.05, -3e5, 0));
}
Also used : EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) Test(org.testng.annotations.Test)

Example 7 with Envelope

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

the class TestGeometrySerialization method testDeserializeType.

@Test
public void testDeserializeType() {
    assertDeserializeType("POINT (1 2)", POINT);
    assertDeserializeType("POINT EMPTY", POINT);
    assertDeserializeType("MULTIPOINT (20 20, 25 25)", MULTI_POINT);
    assertDeserializeType("MULTIPOINT EMPTY", MULTI_POINT);
    assertDeserializeType("LINESTRING (1 1, 5 1, 6 2))", LINE_STRING);
    assertDeserializeType("LINESTRING EMPTY", LINE_STRING);
    assertDeserializeType("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))", MULTI_LINE_STRING);
    assertDeserializeType("MULTILINESTRING EMPTY", MULTI_LINE_STRING);
    assertDeserializeType("POLYGON ((0 0, 0 4, 4 0))", POLYGON);
    assertDeserializeType("POLYGON EMPTY", POLYGON);
    assertDeserializeType("MULTIPOLYGON (((0 0 , 0 2, 2 2, 2 0)), ((2 2, 2 4, 4 4, 4 2)))", MULTI_POLYGON);
    assertDeserializeType("MULTIPOLYGON EMPTY", MULTI_POLYGON);
    assertDeserializeType("GEOMETRYCOLLECTION (POINT (3 7), LINESTRING (4 6, 7 10))", GEOMETRY_COLLECTION);
    assertDeserializeType("GEOMETRYCOLLECTION EMPTY", GEOMETRY_COLLECTION);
    assertEquals(deserializeType(serialize(new Envelope(1, 2, 3, 4))), ENVELOPE);
}
Also used : EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) Test(org.testng.annotations.Test)

Example 8 with Envelope

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

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.isEmpty()) {
        return;
    }
    if (state.getCount() == 0) {
        state.setPartitionCount(toIntExact(partitionCount));
        state.setSamples(new ArrayList<>());
    }
    // use reservoir sampling
    Rectangle extent = new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax());
    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(com.facebook.presto.geospatial.Rectangle) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 9 with Envelope

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

the class BingTileFunctions method appendIntersectingSubtiles.

/**
 * Identifies a minimum set of tiles at specified zoom level that cover intersection of the
 * specified geometry and a specified tile of the same or lower level. Adds tiles to provided
 * BlockBuilder.
 */
private static void appendIntersectingSubtiles(OGCGeometry ogcGeometry, int zoomLevel, BingTile tile, BlockBuilder blockBuilder) {
    int tileZoomLevel = tile.getZoomLevel();
    checkArgument(tileZoomLevel <= zoomLevel);
    Envelope tileEnvelope = tileToEnvelope(tile);
    if (tileZoomLevel == zoomLevel) {
        if (!disjoint(tileEnvelope, ogcGeometry)) {
            BIGINT.writeLong(blockBuilder, tile.encode());
        }
        return;
    }
    if (contains(ogcGeometry, tileEnvelope)) {
        int subTileCount = 1 << (zoomLevel - tileZoomLevel);
        int minX = subTileCount * tile.getX();
        int minY = subTileCount * tile.getY();
        for (int x = minX; x < minX + subTileCount; x++) {
            for (int y = minY; y < minY + subTileCount; y++) {
                BIGINT.writeLong(blockBuilder, BingTile.fromCoordinates(x, y, zoomLevel).encode());
            }
        }
        return;
    }
    if (disjoint(tileEnvelope, ogcGeometry)) {
        return;
    }
    int minX = 2 * tile.getX();
    int minY = 2 * tile.getY();
    int nextZoomLevel = tileZoomLevel + 1;
    verify(nextZoomLevel <= MAX_ZOOM_LEVEL);
    for (int x = minX; x < minX + 2; x++) {
        for (int y = minY; y < minY + 2; y++) {
            appendIntersectingSubtiles(ogcGeometry, zoomLevel, BingTile.fromCoordinates(x, y, nextZoomLevel), blockBuilder);
        }
    }
}
Also used : 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)

Example 10 with Envelope

use of com.esri.core.geometry.Envelope 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

Envelope (com.esri.core.geometry.Envelope)18 EsriGeometrySerde.deserializeEnvelope (com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope)12 SqlType (com.facebook.presto.spi.function.SqlType)7 Point (com.esri.core.geometry.Point)6 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)6 Description (com.facebook.presto.spi.function.Description)6 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 Rectangle (com.facebook.presto.geospatial.Rectangle)4 PrestoException (com.facebook.presto.spi.PrestoException)4 Geometry (com.esri.core.geometry.Geometry)3 SqlNullable (com.facebook.presto.spi.function.SqlNullable)3 Test (org.testng.annotations.Test)3 GeometryCursor (com.esri.core.geometry.GeometryCursor)2 MultiPoint (com.esri.core.geometry.MultiPoint)2 OGCMultiPoint (com.esri.core.geometry.ogc.OGCMultiPoint)2 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 GeometryUtils.disjoint (com.facebook.presto.geospatial.GeometryUtils.disjoint)2 GeometrySerializationType (com.facebook.presto.geospatial.serde.GeometrySerializationType)2 BingTileUtils.tileToEnvelope (com.facebook.presto.plugin.geospatial.BingTileUtils.tileToEnvelope)2