Search in sources :

Example 16 with Envelope

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

the class TestSpatialPartitioningInternalAggregation method getSpatialPartitioning.

private String getSpatialPartitioning(List<OGCGeometry> geometries, int partitionCount) {
    ImmutableList.Builder<Rectangle> rectangles = ImmutableList.builder();
    for (OGCGeometry geometry : geometries) {
        Envelope envelope = new Envelope();
        geometry.getEsriGeometry().queryEnvelope(envelope);
        rectangles.add(new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax()));
    }
    return KdbTreeUtils.toJson(buildKdbTree(roundToInt(geometries.size() * 1.0 / partitionCount, CEILING), rectangles.build()));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ImmutableList(com.google.common.collect.ImmutableList) Rectangle(com.facebook.presto.geospatial.Rectangle) Envelope(com.esri.core.geometry.Envelope)

Example 17 with Envelope

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

the class GeoFunctions method spatialPartitions.

@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a geometry representing a set of points within specified distance from the input geometry")
@SqlType("array(int)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(GEOMETRY_TYPE_NAME) Slice geometry, @SqlType(DOUBLE) double distance) {
    if (isNaN(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN");
    }
    if (isInfinite(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is infinite");
    }
    if (distance < 0) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative");
    }
    Envelope envelope = deserializeEnvelope(geometry);
    if (envelope.isEmpty()) {
        return null;
    }
    Rectangle expandedEnvelope2D = new Rectangle(envelope.getXMin() - distance, envelope.getYMin() - distance, envelope.getXMax() + distance, envelope.getYMax() + distance);
    return spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
Also used : Rectangle(com.facebook.presto.geospatial.Rectangle) PrestoException(com.facebook.presto.spi.PrestoException) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 18 with Envelope

use of com.esri.core.geometry.Envelope in project calcite by apache.

the class GeoFunctions method envelope.

private static Envelope envelope(Geometry g) {
    final Envelope env = new Envelope();
    g.queryEnvelope(env);
    return env;
}
Also used : Envelope(com.esri.core.geometry.Envelope)

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