WithinBoxGeomPF extends GenericSpatialGeomBoxPropertyFunction { @Override protected boolean checkSecondFilter(SpatialArguments spatialArguments, GeometryWrapper targetGeometryWrapper) { GeometryWrapper geometryWrapper = spatialArguments.getGeometryWrapper(); try { return targetGeometryWrapper.within(geometryWrapper); } catch (FactoryException | MismatchedDimensionException | TransformException ex) { throw new ExprEvalException(ex.getMessage() + ": " + targetGeometryWrapper.asLiteral() + ", " + geometryWrapper.asLiteral(), ex); } }    }
@Test public void testCheckSecondFilter() { WithinBoxGeomPF instance = new WithinBoxGeomPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_GEOM_PROP); float lat = 1; float lon = 1; float latMin = 0; float lonMin = 0; float latMax = 2; float lonMax = 2; Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); Literal targetGeometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode()); PropFuncArg object = new PropFuncArg(objectNodes); SpatialArguments spatialArguments = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); GeometryWrapper targetGeometryWrapper = GeometryWrapper.extract(targetGeometry); boolean expResult = true; boolean result = instance.checkSecondFilter(spatialArguments, targetGeometryWrapper); assertEquals(expResult, result); }
@Test public void testCheckSecondFilter_fail() { WithinBoxGeomPF instance = new WithinBoxGeomPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_GEOM_PROP); float lat = 5; float lon = 5; float latMin = 0; float lonMin = 0; float latMax = 2; float lonMax = 2; Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); Literal targetGeometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode()); PropFuncArg object = new PropFuncArg(objectNodes); SpatialArguments spatialArguments = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); GeometryWrapper targetGeometryWrapper = GeometryWrapper.extract(targetGeometry); boolean expResult = false; boolean result = instance.checkSecondFilter(spatialArguments, targetGeometryWrapper); assertEquals(expResult, result); }