/** {@inheritDoc } */ @Override public boolean evaluate(final Object object) { Geometry leftGeom = toGeometry(object, left); Geometry rightGeom = toGeometry(object, right); if (leftGeom == null || rightGeom == null) { return false; } final Geometry[] values; try { values = toSameCRS(leftGeom, rightGeom); } catch (FactoryException | TransformException ex) { Logging.getLogger("org.geotoolkit.filter.binaryspatial").log(Level.WARNING, null, ex); return false; } leftGeom = values[0]; rightGeom = values[1]; final Envelope envLeft = leftGeom.getEnvelopeInternal(); final Envelope envRight = rightGeom.getEnvelopeInternal(); if (envLeft.intersects(envRight)) { return leftGeom.overlaps(rightGeom); } return false; }
@Test public void testOverlaps() throws NoSuchIdentifierException, ProcessException { GeometryFactory fact = new GeometryFactory(); // Inputs first final LinearRing ring = fact.createLinearRing( new Coordinate[] { new Coordinate(0.0, 0.0), new Coordinate(0.0, 10.0), new Coordinate(5.0, 10.0), new Coordinate(5.0, 0.0), new Coordinate(0.0, 0.0) }); final Geometry geom1 = fact.createPolygon(ring, null); final LinearRing ring2 = fact.createLinearRing( new Coordinate[] { new Coordinate(-5.0, 0.0), new Coordinate(-5.0, 10.0), new Coordinate(2.0, 10.0), new Coordinate(2.0, 0.0), new Coordinate(-5.0, 0.0) }); final Geometry geom2 = fact.createPolygon(ring2, null); // Process final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("jts", "overlaps"); final ParameterValueGroup in = desc.getInputDescriptor().createValue(); in.parameter("geom1").setValue(geom1); in.parameter("geom2").setValue(geom2); final org.geotoolkit.process.Process proc = desc.createProcess(in); // result final Boolean result = (Boolean) proc.call().parameter("result").getValue(); final Boolean expected = geom1.overlaps(geom2); assertTrue(expected.equals(result)); }
@Test public void testOverlapsCRS() throws NoSuchIdentifierException, ProcessException { GeometryFactory fact = new GeometryFactory(); // Inputs first final LinearRing ring = fact.createLinearRing( new Coordinate[] { new Coordinate(0.0, 0.0), new Coordinate(0.0, 10.0), new Coordinate(5.0, 10.0), new Coordinate(5.0, 0.0), new Coordinate(0.0, 0.0) }); final Geometry geom1 = fact.createPolygon(ring, null); final LinearRing ring2 = fact.createLinearRing( new Coordinate[] { new Coordinate(-5.0, 0.0), new Coordinate(-5.0, 10.0), new Coordinate(2.0, 10.0), new Coordinate(2.0, 0.0), new Coordinate(-5.0, 0.0) }); Geometry geom2 = fact.createPolygon(ring2, null); CoordinateReferenceSystem crs1 = null; try { crs1 = CRS.decode("EPSG:4326"); JTS.setCRS(geom1, crs1); } catch (FactoryException ex) { Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex); } CoordinateReferenceSystem crs2 = null; try { crs2 = CRS.decode("EPSG:4326"); JTS.setCRS(geom2, crs2); } catch (FactoryException ex) { Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex); } // Process final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("jts", "overlaps"); final ParameterValueGroup in = desc.getInputDescriptor().createValue(); in.parameter("geom1").setValue(geom1); in.parameter("geom2").setValue(geom2); final org.geotoolkit.process.Process proc = desc.createProcess(in); // result final Boolean result = (Boolean) proc.call().parameter("result").getValue(); MathTransform mt = null; try { mt = CRS.findMathTransform(crs2, crs1); geom2 = JTS.transform(geom2, mt); } catch (FactoryException ex) { Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex); } catch (TransformException ex) { Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex); } final Boolean expected = geom1.overlaps(geom2); assertTrue(expected.equals(result)); }
/** * Returns a boolean value that shows if this geometry overlaps the specified geometry. * * @param node1 xml element containing gml object(s) * @param node2 xml element containing gml object(s) * @return boolean value * @throws QueryException query exception */ @Deterministic public Bln overlaps(final ANode node1, final ANode node2) throws QueryException { final Geometry geo1 = checkGeo(node1); final Geometry geo2 = checkGeo(node2); return Bln.get(geo1.overlaps(geo2)); }