Search in sources :

Example 11 with Envelope

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

the class BingTileUtils method findRawTileCovering.

private static List<BingTile> findRawTileCovering(OGCGeometry ogcGeometry, int maxZoom) {
    Envelope envelope = getEnvelope(ogcGeometry);
    Optional<List<BingTile>> trivialResult = handleTrivialCases(envelope, maxZoom);
    if (trivialResult.isPresent()) {
        return trivialResult.get();
    }
    accelerateGeometry(ogcGeometry, OperatorIntersects.local(), Geometry.GeometryAccelerationDegree.enumMedium);
    Deque<TilingEntry> stack = new ArrayDeque<>();
    Consumer<BingTile> addIntersecting = tile -> {
        TilingEntry tilingEntry = new TilingEntry(tile);
        if (satisfiesTileEdgeCondition(envelope, tilingEntry) && ogcGeometry.intersects(tilingEntry.polygon)) {
            stack.push(tilingEntry);
        }
    };
    // Populate with initial tiles.  Since there aren't many low zoom tiles,
    // and throwing away totally disjoint ones is cheap (envelope check),
    // we might as well start comprehensively.
    ImmutableList.of(BingTile.fromCoordinates(0, 0, 1), BingTile.fromCoordinates(0, 1, 1), BingTile.fromCoordinates(1, 0, 1), BingTile.fromCoordinates(1, 1, 1)).forEach(addIntersecting);
    List<BingTile> outputTiles = new ArrayList<>();
    while (!stack.isEmpty()) {
        TilingEntry entry = stack.pop();
        if (entry.tile.getZoomLevel() == maxZoom || ogcGeometry.contains(entry.polygon)) {
            outputTiles.add(entry.tile);
        } else {
            entry.tile.findChildren().forEach(addIntersecting);
            checkCondition(outputTiles.size() + stack.size() <= MAX_COVERING_COUNT, "The zoom level is too high or the geometry is too large to compute a set " + "of covering Bing tiles. Please use a lower zoom level, or tile only a section " + "of the geometry.");
        }
    }
    return outputTiles;
}
Also used : StandardTypes(com.facebook.presto.common.type.StandardTypes) Slice(io.airlift.slice.Slice) PriorityQueue(java.util.PriorityQueue) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) PrestoException(com.facebook.presto.spi.PrestoException) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) INVALID_FUNCTION_ARGUMENT(com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT) Point(com.esri.core.geometry.Point) OperatorIntersects(com.esri.core.geometry.OperatorIntersects) Set(java.util.Set) Geometry(com.esri.core.geometry.Geometry) String.format(java.lang.String.format) Consumer(java.util.function.Consumer) List(java.util.List) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.accelerateGeometry(com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry) MAX_ZOOM_LEVEL(com.facebook.presto.plugin.geospatial.BingTile.MAX_ZOOM_LEVEL) Optional(java.util.Optional) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) GeometryUtils.getEnvelope(com.facebook.presto.geospatial.GeometryUtils.getEnvelope) SqlType(com.facebook.presto.spi.function.SqlType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.getEnvelope(com.facebook.presto.geospatial.GeometryUtils.getEnvelope) ArrayDeque(java.util.ArrayDeque)

Example 12 with Envelope

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

the class GeometryUtils method getEnvelope.

public static Envelope getEnvelope(OGCGeometry ogcGeometry) {
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    Envelope overallEnvelope = new Envelope();
    while (true) {
        Geometry geometry = cursor.next();
        if (geometry == null) {
            return overallEnvelope;
        }
        Envelope envelope = new Envelope();
        geometry.queryEnvelope(envelope);
        overallEnvelope.merge(envelope);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) Geometry(com.esri.core.geometry.Geometry) GeometryCursor(com.esri.core.geometry.GeometryCursor) Envelope(com.esri.core.geometry.Envelope)

Example 13 with Envelope

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

the class EsriGeometrySerde method getSimpleGeometryEnvelope.

private static Envelope getSimpleGeometryEnvelope(BasicSliceInput input, int length) {
    // skip type injected by esri
    input.readInt();
    Envelope envelope = readEnvelope(input);
    int skipLength = length - (4 * Double.BYTES) - Integer.BYTES;
    verify(input.skip(skipLength) == skipLength);
    return envelope;
}
Also used : Envelope(com.esri.core.geometry.Envelope) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Example 14 with Envelope

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

the class EsriGeometrySerde method getGeometryCollectionOverallEnvelope.

private static Envelope getGeometryCollectionOverallEnvelope(BasicSliceInput input) {
    Envelope overallEnvelope = new Envelope();
    while (input.available() > 0) {
        int length = input.readInt() - 1;
        GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());
        Envelope envelope = getEnvelope(input, type, length);
        overallEnvelope = merge(overallEnvelope, envelope);
    }
    return overallEnvelope;
}
Also used : Envelope(com.esri.core.geometry.Envelope) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Example 15 with Envelope

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

the class TestGeometrySerialization method testDeserializeEnvelope.

@Test
public void testDeserializeEnvelope() {
    assertDeserializeEnvelope("MULTIPOINT (20 20, 25 25)", new Envelope(20, 20, 25, 25));
    assertDeserializeEnvelope("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))", new Envelope(1, 1, 5, 4));
    assertDeserializeEnvelope("POLYGON ((0 0, 0 4, 4 0))", new Envelope(0, 0, 4, 4));
    assertDeserializeEnvelope("MULTIPOLYGON (((0 0 , 0 2, 2 2, 2 0)), ((2 2, 2 4, 4 4, 4 2)))", new Envelope(0, 0, 4, 4));
    assertDeserializeEnvelope("GEOMETRYCOLLECTION (POINT (3 7), LINESTRING (4 6, 7 10))", new Envelope(3, 6, 7, 10));
    assertDeserializeEnvelope("POLYGON EMPTY", new Envelope());
    assertDeserializeEnvelope("POINT (1 2)", new Envelope(1, 2, 1, 2));
    assertDeserializeEnvelope("POINT EMPTY", new Envelope());
    assertDeserializeEnvelope("GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (2 7), LINESTRING (4 6, 7 10)), POINT (3 7), LINESTRING (4 6, 7 10))", new Envelope(2, 6, 7, 10));
}
Also used : EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) Test(org.testng.annotations.Test)

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