GenericSpatialBoxPropertyFunction extends GenericSpatialGeomPropertyFunction { @Override protected SpatialArguments extractObjectArguments(Node predicate, PropFuncArg object, SRSInfo indexSRSInfo) { try { List<Node> objectArgs = object.getArgList(); if (objectArgs.size() < 4) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Minimum of 4 arguments."); } else if (objectArgs.size() > 5) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 5 arguments."); } Node latMin = objectArgs.get(LAT_MIN_POS); Node lonMin = objectArgs.get(LON_MIN_POS); Node latMax = objectArgs.get(LAT_MAX_POS); Node lonMax = objectArgs.get(LON_MAX_POS); if (latMin.isVariable() || lonMin.isVariable() || latMax.isVariable() || lonMax.isVariable()) { throw new ExprEvalException("Arguments are not all concrete: " + FmtUtils.stringForNode(latMin) + ", " + FmtUtils.stringForNode(lonMin) + FmtUtils.stringForNode(latMax) + ", " + FmtUtils.stringForNode(lonMax)); } 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.getNode())); } limit = limitNode.getInteger().intValue(); } else { limit = DEFAULT_LIMIT; } Node geometryNode = ConvertLatLonBox.toNode(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometryNode); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, indexSRSInfo); return new SpatialArguments(limit, geometryWrapper, searchEnvelope); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }    }
@Test public void testExtractObjectArguments_5args() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeFloat(lonMax).asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); 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_4args() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = -1; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeFloat(lonMax).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); 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() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_6args_fail() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeFloat(lonMax).asNode(), NodeValue.makeInteger(limit).asNode(), NodeValue.makeBoolean(false).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_5args_pos0_fail() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeString("e").asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeFloat(lonMax).asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_5args_pos1_fail() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeString("e").asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeFloat(lonMax).asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_5args_pos2_fail() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeString("e").asNode(), NodeValue.makeFloat(lonMax).asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_5args_pos3_fail() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeString("e").asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }
@Test(expected = ExprEvalException.class) public void testExtractObjectArguments_5args_pos4_fail() { GenericSpatialBoxPropertyFunction instance = new WithinBoxPF(); Node predicate = NodeFactory.createURI(SpatialExtension.WITHIN_BOX_PROP); float latMin = 0; float lonMin = 1; float latMax = 2; float lonMax = 3; int limit = 10; List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(latMin).asNode(), NodeValue.makeFloat(lonMin).asNode(), NodeValue.makeFloat(latMax).asNode(), NodeValue.makeFloat(lonMax).asNode(), NodeValue.makeString("10").asNode()); PropFuncArg object = new PropFuncArg(objectNodes); Literal geometry = ConvertLatLonBox.toLiteral(latMin, lonMin, latMax, lonMax); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }