GenericSpatialGeomPropertyFunction extends GenericSpatialPropertyFunction { @Override protected SpatialArguments extractObjectArguments(Node predicate, PropFuncArg object, SRSInfo indexSRSInfo) { try { List<Node> objectArgs = object.getArgList(); if (objectArgs.size() < 1) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Minimum of 1 arguments."); } else if (objectArgs.size() > 2) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 2 arguments."); } Node geomLit = object.getArg(GEOM_POS); int limit; if (objectArgs.size() > LIMIT_POS) { NodeValue limitNode = NodeValue.makeNode(objectArgs.get(LIMIT_POS)); if (!limitNode.isInteger()) { throw new ExprEvalException("Not an integer: " + FmtUtils.stringForNode(limitNode.asNode())); } limit = limitNode.getInteger().intValue(); } else { limit = DEFAULT_LIMIT; } GeometryWrapper geometryWrapper = GeometryWrapper.extract(geomLit); SearchEnvelope searchEnvelope = buildSearchEnvelope(geometryWrapper, indexSRSInfo); return new SpatialArguments(limit, geometryWrapper, searchEnvelope); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }    }
@Test public void testExtractObjectArguments_2args() { Node predicate = NodeFactory.createURI(SpatialExtension.INTERSECT_BOX_GEOM_PROP); float lat = 0.0f; float lon = 1.0f; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); GenericSpatialGeomPropertyFunction instance = new IntersectBoxGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); assertEquals(expResult, result); }
@Test public void testExtractObjectArguments_1args() { Node predicate = NodeFactory.createURI(SpatialExtension.INTERSECT_BOX_GEOM_PROP); float lat = 0.0f; float lon = 1.0f; int limit = -1; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); GenericSpatialGeomPropertyFunction instance = new IntersectBoxGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_0args_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.INTERSECT_BOX_GEOM_PROP); float lat = 0.0f; float lon = 1.0f; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); GenericSpatialGeomPropertyFunction instance = new IntersectBoxGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_3args_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.INTERSECT_BOX_GEOM_PROP); float lat = 0.0f; float lon = 1.0f; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeInteger(limit).asNode(), NodeValue.makeBoolean(false).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); GenericSpatialGeomPropertyFunction instance = new IntersectBoxGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_2args_pos0_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.INTERSECT_BOX_GEOM_PROP); float lat = 0.0f; float lon = 1.0f; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeString("Geometry").asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); GenericSpatialGeomPropertyFunction instance = new IntersectBoxGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_2args_pos1_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.INTERSECT_BOX_GEOM_PROP); float lat = 0.0f; float lon = 1.0f; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeString("10").asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); GenericSpatialGeomPropertyFunction instance = new IntersectBoxGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); assertEquals(expResult, result); }