GenericCardinalPropertyFunction extends GenericCardinalGeomPropertyFunction { @Override protected SpatialArguments extractObjectArguments(Node predicate, PropFuncArg object, SRSInfo indexSRSInfo) { try { List<Node> objectArgs = object.getArgList(); if (objectArgs.size() < 2) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Minimum of 2 arguments."); } else if (objectArgs.size() > 3) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 3 arguments."); } Node lat = objectArgs.get(LAT_POS); Node lon = objectArgs.get(LON_POS); if (lat.isVariable() || lon.isVariable()) { throw new ExprEvalException("Arguments are not all concrete: " + FmtUtils.stringForNode(lat) + ", " + FmtUtils.stringForNode(lon)); } 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; } GeometryWrapper geometryWrapper = ConvertLatLon.toGeometryWrapper(lat, lon); SearchEnvelope searchEnvelope = buildSearchEnvelope(geometryWrapper, indexSRSInfo); return new SpatialArguments(limit, geometryWrapper, searchEnvelope); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }    }
@Test public void testExtractObjectArguments_3args() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode(), NodeValue.makeFloat(lon).asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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_2args() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = -1; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode(), NodeValue.makeFloat(lon).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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_1args_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = -1; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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_4args_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode(), NodeValue.makeFloat(lon).asNode(), NodeValue.makeInteger(limit).asNode(), NodeValue.makeBoolean(false).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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_pos0_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeString("e").asNode(), NodeValue.makeFloat(lon).asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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_pos1_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode(), NodeValue.makeString("e").asNode(), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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_pos2_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NORTH_PROP); float lat = 0; float lon = 1; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode(), NodeValue.makeFloat(lon).asNode(), NodeValue.makeString("10").asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); NorthPF instance = new NorthPF(); SearchEnvelope searchEnvelope = instance.buildSearchEnvelope(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); }