return (buildGeometry, probeGeometry, radius) -> buildGeometry.intersects(probeGeometry); case ST_DISTANCE: if (comparisonOperator.get() == LESS_THAN) {
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1; com.esri.core.geometry.ogc.OGCGeometry geom2; geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); geom2 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); out.value = geom1.intersects(geom2) ? 1 : 0; } }
@SqlNullable @Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)") @ScalarFunction("ST_Intersects") @SqlType(BOOLEAN) public static Boolean stIntersects(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) { if (!envelopes(left, right, Envelope::intersect)) { return false; } OGCGeometry leftGeometry = deserialize(left); OGCGeometry rightGeometry = deserialize(right); verifySameSpatialReference(leftGeometry, rightGeometry); return leftGeometry.intersects(rightGeometry); }
@Test public void testDistributedSpatialSelfJoin() { TaskContext taskContext = createTaskContext(); DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext(); RowPagesBuilder pages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER)) .row(POLYGON_A, "A", 1) .row(POLYGON_A, "A", 2) .row(null, "null", null) .pageBreak() .row(POLYGON_B, "B", 0) .row(POLYGON_B, "B", 2); MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)) .row("A", "A") .row("A", "B") .row("B", "A") .row("B", "B") .build(); PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), pages); OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, pages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory); assertOperatorEquals(joinOperatorFactory, driverContext, pages.build(), expected); }
@Override protected Object evaluateOGCGeometry(OGCGeometry geometry0, OGCGeometry geometry1) throws HyracksDataException { return geometry0.intersects(geometry1); }
return (buildGeometry, probeGeometry, radius) -> buildGeometry.intersects(probeGeometry); case ST_DISTANCE: if (comparisonOperator.get() == LESS_THAN) {
return (buildGeometry, probeGeometry, radius) -> buildGeometry.intersects(probeGeometry); case ST_DISTANCE: if (comparisonOperator.get() == LESS_THAN) {
@Override public Boolean exec(Tuple input) throws IOException { OGCGeometry geom1 = null, geom2 = null; try { geom1 = geometryParser.parseGeom(input.get(0)); geom2 = geometryParser.parseGeom(input.get(1)); return geom1.intersects(geom2); } catch (ExecException ee) { throw new GeoException(geom1, geom2, ee); } }
@Override public boolean isIntersected(Shape s) { Rectangle s_mbr = s.getMBR(); Rectangle this_mbr = this.getMBR(); if (s_mbr == null || this_mbr == null) return false; // Filter step if (!s_mbr.isIntersected(this_mbr)) return false; try { if (s instanceof OGCESRIShape) return geom.intersects(((OGCESRIShape)s).geom); } catch (NullPointerException e) { // TODO Auto-generated catch block e.printStackTrace(); } ArrayList<OGCGeometry> points = new ArrayList<OGCGeometry>(); points.add(new OGCPoint(new com.esri.core.geometry.Point(s_mbr.x1, s_mbr.y1), geom.getEsriSpatialReference())); points.add(new OGCPoint(new com.esri.core.geometry.Point(s_mbr.x2, s_mbr.y2), geom.getEsriSpatialReference())); OGCGeometryCollection all_points = new OGCConcreteGeometryCollection(points, geom.getEsriSpatialReference()); return geom.intersects(all_points.envelope()); }
@SqlNullable @Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)") @ScalarFunction("ST_Intersects") @SqlType(BOOLEAN) public static Boolean stIntersects(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) { if (!envelopes(left, right, Envelope::intersect)) { return false; } OGCGeometry leftGeometry = deserialize(left); OGCGeometry rightGeometry = deserialize(right); verifySameSpatialReference(leftGeometry, rightGeometry); return leftGeometry.intersects(rightGeometry); }
@SqlNullable @Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)") @ScalarFunction("ST_Intersects") @SqlType(BOOLEAN) public static Boolean stIntersects(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) { if (!envelopes(left, right, Envelope::intersect)) { return false; } OGCGeometry leftGeometry = deserialize(left); OGCGeometry rightGeometry = deserialize(right); verifySameSpatialReference(leftGeometry, rightGeometry); return leftGeometry.intersects(rightGeometry); }
@Test public void testDistributedSpatialSelfJoin() { TaskContext taskContext = createTaskContext(); DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext(); RowPagesBuilder pages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER)) .row(POLYGON_A, "A", 1) .row(POLYGON_A, "A", 2) .row(null, "null", null) .pageBreak() .row(POLYGON_B, "B", 0) .row(POLYGON_B, "B", 2); MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)) .row("A", "A") .row("A", "B") .row("B", "A") .row("B", "B") .build(); PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), pages); OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, pages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory); assertOperatorEquals(joinOperatorFactory, driverContext, pages.build(), expected); }
@Test public void testDistributedSpatialSelfJoin() { TaskContext taskContext = createTaskContext(); DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext(); RowPagesBuilder pages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER)) .row(POLYGON_A, "A", 1) .row(POLYGON_A, "A", 2) .row(null, "null", null) .pageBreak() .row(POLYGON_B, "B", 0) .row(POLYGON_B, "B", 2); MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)) .row("A", "A") .row("A", "B") .row("B", "A") .row("B", "B") .build(); PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), pages); OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, pages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory); assertOperatorEquals(joinOperatorFactory, driverContext, pages.build(), expected); }