Search in sources :

Example 51 with OGCGeometry

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

the class GeoFunctions method stOverlaps.

@SqlNullable
@Description("Returns TRUE if the Geometries share space, are of the same dimension, but are not completely contained by each other")
@ScalarFunction("ST_Overlaps")
@SqlType(BOOLEAN)
public static Boolean stOverlaps(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    if (!envelopes(left, right, Envelope::intersect)) {
        return false;
    }
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.overlaps(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 52 with OGCGeometry

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

the class PagesRTreeIndex method findJoinPositions.

/**
 * Returns an array of addresses from {@link PagesIndex#getValueAddresses()} corresponding
 * to rows with matching geometries.
 * <p>
 * The caller is responsible for calling {@link #isJoinPositionEligible(int, int, Page)}
 * for each of these addresses to apply additional join filters.
 */
@Override
public int[] findJoinPositions(int probePosition, Page probe, int probeGeometryChannel, Optional<Integer> probePartitionChannel) {
    Block probeGeometryBlock = probe.getBlock(probeGeometryChannel);
    if (probeGeometryBlock.isNull(probePosition)) {
        return EMPTY_ADDRESSES;
    }
    int probePartition = probePartitionChannel.map(channel -> toIntExact(INTEGER.getLong(probe.getBlock(channel), probePosition))).orElse(-1);
    Slice slice = probeGeometryBlock.getSlice(probePosition, 0, probeGeometryBlock.getSliceLength(probePosition));
    OGCGeometry probeGeometry = deserialize(slice);
    verify(probeGeometry != null);
    if (probeGeometry.isEmpty()) {
        return EMPTY_ADDRESSES;
    }
    IntArrayList matchingPositions = new IntArrayList();
    Rectangle queryRectangle = getExtent(probeGeometry);
    boolean probeIsPoint = queryRectangle.isPointlike();
    rtree.findIntersections(queryRectangle, geometryWithPosition -> {
        OGCGeometry buildGeometry = geometryWithPosition.getGeometry();
        Rectangle buildEnvelope = geometryWithPosition.getExtent();
        if (partitions.isEmpty() || (probePartition == geometryWithPosition.getPartition() && (probeIsPoint || buildEnvelope.isPointlike() || testReferencePoint(queryRectangle, buildEnvelope, probePartition)))) {
            OptionalDouble radius = radiusChannel == -1 ? OptionalDouble.empty() : OptionalDouble.of(getRadius(geometryWithPosition.getPosition()));
            if (spatialRelationshipTest.apply(buildGeometry, probeGeometry, radius)) {
                matchingPositions.add(geometryWithPosition.getPosition());
            }
        }
    });
    return matchingPositions.toIntArray();
}
Also used : Page(com.facebook.presto.common.Page) Slice(io.airlift.slice.Slice) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OptionalDouble(java.util.OptionalDouble) PageBuilder(com.facebook.presto.common.PageBuilder) HasExtent(com.facebook.presto.geospatial.rtree.HasExtent) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray) GeometryUtils(com.facebook.presto.geospatial.GeometryUtils) JoinUtils.channelsToPages(com.facebook.presto.operator.JoinUtils.channelsToPages) Math.toIntExact(java.lang.Math.toIntExact) SyntheticAddress.decodePosition(com.facebook.presto.operator.SyntheticAddress.decodePosition) Type(com.facebook.presto.common.type.Type) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Session(com.facebook.presto.Session) GeometryUtils.getExtent(com.facebook.presto.geospatial.GeometryUtils.getExtent) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush) Rectangle(com.facebook.presto.geospatial.Rectangle) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) EsriGeometrySerde.deserialize(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SyntheticAddress.decodeSliceIndex(com.facebook.presto.operator.SyntheticAddress.decodeSliceIndex) Optional(java.util.Optional) Block(com.facebook.presto.common.block.Block) SpatialPredicate(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialPredicate) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) JoinFilterFunctionFactory(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Slice(io.airlift.slice.Slice) Rectangle(com.facebook.presto.geospatial.Rectangle) Block(com.facebook.presto.common.block.Block) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) OptionalDouble(java.util.OptionalDouble)

Example 53 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project pigeon by aseldawy.

the class TestHelper method assertGeometryEqual.

public static void assertGeometryEqual(Object expected, Object test) {
    OGCGeometry expected_geom = expected instanceof String ? OGCGeometry.fromText((String) expected) : OGCGeometry.fromBinary(ByteBuffer.wrap(((DataByteArray) expected).get()));
    OGCGeometry test_geom = test instanceof String ? OGCGeometry.fromText((String) test) : OGCGeometry.fromBinary(ByteBuffer.wrap(((DataByteArray) test).get()));
    if (expected_geom instanceof OGCGeometryCollection && test_geom instanceof OGCGeometryCollection) {
        OGCGeometryCollection expected_coln = (OGCGeometryCollection) expected_geom;
        OGCGeometryCollection test_coln = (OGCGeometryCollection) test_geom;
        assertEquals(expected_coln.numGeometries(), test_coln.numGeometries());
        Vector<OGCGeometry> expectedGeometries = new Vector<OGCGeometry>();
        for (int i = 0; i < expected_coln.numGeometries(); i++) {
            expectedGeometries.add(expected_coln.geometryN(i));
        }
        for (int i = 0; i < test_coln.numGeometries(); i++) {
            OGCGeometry geom = test_coln.geometryN(i);
            int j = 0;
            while (j < expectedGeometries.size() && !geom.equals(expectedGeometries.get(j))) j++;
            assertTrue(j < expectedGeometries.size());
            expectedGeometries.remove(j++);
        }
    } else {
        assertTrue("Exepcted geometry to be '" + expected + "' but found '" + test + "'", expected_geom.equals(test_geom));
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometryCollection(com.esri.core.geometry.ogc.OGCGeometryCollection) Vector(java.util.Vector)

Example 54 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project pigeon by aseldawy.

the class TestGeometryParser method testShouldReturnNullOnNullInput.

public void testShouldReturnNullOnNullInput() throws Exception {
    OGCGeometry parsed = geometry_parser.parseGeom(null);
    assertNull(parsed);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry)

Example 55 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project pigeon by aseldawy.

the class TestGeometryParser method testShouldParseWKT.

public void testShouldParseWKT() throws Exception {
    String wkt = polygon.asText();
    OGCGeometry parsed = geometry_parser.parseGeom(wkt);
    assertTrue(polygon.equals(parsed));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry)

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