NearbyGeomPF extends GenericSpatialPropertyFunction { @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() > 4) { throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 4 arguments."); } Node geomLit = object.getArg(GEOM_POS); NodeValue radiusNode = NodeValue.makeNode(objectArgs.get(RADIUS_POS)); if (!radiusNode.isDouble()) { throw new ExprEvalException("Not a xsd:double: " + FmtUtils.stringForNode(radiusNode.asNode())); } radius = radiusNode.getDouble(); if (objectArgs.size() > UNITS_POS) { Node unitsNode = objectArgs.get(UNITS_POS); if (!unitsNode.isURI()) { throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(unitsNode)); } unitsURI = unitsNode.getURI(); } else { unitsURI = NearbyPF.DEFAULT_UNITS; } 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 = SearchEnvelope.build(geometryWrapper, indexSRSInfo, radius, unitsURI); return new SpatialArguments(limit, geometryWrapper, searchEnvelope); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }    }
@Test public void testExtractObjectArguments_4args() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeFloat(radius).asNode(), NodeFactory.createURI(unitsURI), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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_3args() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = -1; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeFloat(radius).asNode(), NodeFactory.createURI(unitsURI)); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5; String unitsURI = Unit_URI.KILOMETER_URL; int limit = -1; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeFloat(radius).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5; String unitsURI = Unit_URI.KILOMETER_URL; 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, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeFloat(radius).asNode(), NodeFactory.createURI(unitsURI), 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, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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_4args_pos0_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeString("0").asNode(), NodeValue.makeFloat(lon).asNode(), NodeValue.makeFloat(radius).asNode(), NodeFactory.createURI(unitsURI), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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_4args_pos1_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(NodeValue.makeFloat(lat).asNode(), NodeValue.makeString("1").asNode(), NodeValue.makeFloat(radius).asNode(), NodeFactory.createURI(unitsURI), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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_4args_pos2_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeString("5000").asNode(), NodeFactory.createURI(unitsURI), NodeValue.makeInteger(limit).asNode()); PropFuncArg object = new PropFuncArg(objectNodes); GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometry); SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, SpatialIndexTestData.WGS_84_SRS_INFO, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); 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_4args_pos3_fail() { Node predicate = NodeFactory.createURI(SpatialExtension.NEARBY_GEOM_PROP); float lat = 0; float lon = 1; float radius = 5000; String unitsURI = Unit_URI.METRE_URL; int limit = 10; Literal geometry = ConvertLatLon.toLiteral(lat, lon); List<Node> objectNodes = Arrays.asList(geometry.asNode(), NodeValue.makeFloat(radius).asNode(), NodeValue.makeString(unitsURI).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, radius, unitsURI); NearbyGeomPF instance = new NearbyGeomPF(); SpatialArguments expResult = new SpatialArguments(limit, geometryWrapper, searchEnvelope); SpatialArguments result = instance.extractObjectArguments(predicate, object, SpatialIndexTestData.WGS_84_SRS_INFO); }