Search in sources :

Example 46 with OGCGeometry

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

the class AbstractTestGeoAggregationFunctions method assertAggregatedGeometries.

protected void assertAggregatedGeometries(String testDescription, String expectedWkt, String... wkts) {
    List<Slice> geometrySlices = Arrays.stream(wkts).map(text -> text == null ? null : OGCGeometry.fromText(text)).map(input -> input == null ? null : EsriGeometrySerde.serialize(input)).collect(Collectors.toList());
    // Add a custom equality assertion because the resulting geometry may have
    // its constituent points in a different order
    BiFunction<Object, Object, Boolean> equalityFunction = (left, right) -> {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        OGCGeometry leftGeometry = OGCGeometry.fromText(left.toString());
        OGCGeometry rightGeometry = OGCGeometry.fromText(right.toString());
        // Check for equality by getting the difference
        return leftGeometry.difference(rightGeometry).isEmpty() && rightGeometry.difference(leftGeometry).isEmpty();
    };
    // Test in forward and reverse order to verify that ordering doesn't affect the output
    assertAggregation(function, equalityFunction, testDescription, new Page(BlockAssertions.createSlicesBlock(geometrySlices)), expectedWkt);
    Collections.reverse(geometrySlices);
    assertAggregation(function, equalityFunction, testDescription, new Page(BlockAssertions.createSlicesBlock(geometrySlices)), expectedWkt);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) GEOMETRY(com.facebook.presto.plugin.geospatial.GeometryType.GEOMETRY) Page(com.facebook.presto.common.Page) Arrays(java.util.Arrays) Slice(io.airlift.slice.Slice) AbstractTestFunctions(com.facebook.presto.operator.scalar.AbstractTestFunctions) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) BeforeClass(org.testng.annotations.BeforeClass) BiFunction(java.util.function.BiFunction) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Collectors(java.util.stream.Collectors) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) EsriGeometrySerde(com.facebook.presto.geospatial.serde.EsriGeometrySerde) FunctionExtractor.extractFunctions(com.facebook.presto.metadata.FunctionExtractor.extractFunctions) BlockAssertions(com.facebook.presto.block.BlockAssertions) List(java.util.List) GeoPlugin(com.facebook.presto.plugin.geospatial.GeoPlugin) Collections(java.util.Collections) Type(com.facebook.presto.common.type.Type) AggregationTestUtils.assertAggregation(com.facebook.presto.operator.aggregation.AggregationTestUtils.assertAggregation) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Slice(io.airlift.slice.Slice) Page(com.facebook.presto.common.Page)

Example 47 with OGCGeometry

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

the class TestGeometryStateFactory method testMemoryAccounting.

@Test
public void testMemoryAccounting() {
    GeometryState state = factory.createGroupedState();
    long oldSize = state.getEstimatedSize();
    OGCGeometry geometry = OGCGeometry.fromText("POLYGON ((2 2, 1 1, 3 1, 2 2))");
    long previousGeometryMemorySize = 0;
    state.setGeometry(geometry, previousGeometryMemorySize);
    assertTrue(oldSize < state.getEstimatedSize(), format("Expected old size %s to be less than new estimate %s", oldSize, state.getEstimatedSize()));
    oldSize = state.getEstimatedSize();
    previousGeometryMemorySize = state.getGeometry().estimateMemorySize();
    state.setGeometry(state.getGeometry().union(geometry), previousGeometryMemorySize);
    assertTrue(oldSize <= state.getEstimatedSize(), format("Expected old size %s to be less than or equal to new estimate %s", oldSize, state.getEstimatedSize()));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Test(org.testng.annotations.Test)

Example 48 with OGCGeometry

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

the class GeoFunctions method stWithin.

@SqlNullable
@Description("Returns TRUE if the geometry A is completely inside geometry B")
@ScalarFunction("ST_Within")
@SqlType(BOOLEAN)
public static Boolean stWithin(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(right, left, Envelope::contains)) {
        return false;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.within(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) 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 49 with OGCGeometry

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

the class GeoFunctions method stDisjoint.

@SqlNullable
@Description("Returns TRUE if the Geometries do not spatially intersect - if they do not share any space together")
@ScalarFunction("ST_Disjoint")
@SqlType(BOOLEAN)
public static Boolean stDisjoint(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::intersect)) {
        return true;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.disjoint(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) 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 50 with OGCGeometry

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

the class GeoFunctions method stContains.

@SqlNullable
@Description("Returns TRUE if and only if no points of right lie in the exterior of left, and at least one point of the interior of left lies in the interior of right")
@ScalarFunction("ST_Contains")
@SqlType(BOOLEAN)
public static Boolean stContains(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::contains)) {
        return false;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.contains(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) 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)

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