SpatialObjectGeometryLiteral { protected static final SpatialObjectGeometryLiteral retrieve(Graph graph, Node targetSpatialObject) { Node geometry = null; if (graph.contains(targetSpatialObject, RDF.type.asNode(), Geo.FEATURE_NODE)) { ExtendedIterator<Triple> geomIter = graph.find(targetSpatialObject, Geo.HAS_DEFAULT_GEOMETRY_NODE, null); geometry = extractObject(geomIter); } else if (graph.contains(targetSpatialObject, RDF.type.asNode(), Geo.GEOMETRY_NODE)) { geometry = targetSpatialObject; } if (geometry != null) { ExtendedIterator<Triple> iter = graph.find(geometry, Geo.HAS_SERIALIZATION_NODE, null); Node literalNode = extractObject(iter); if (literalNode == null) { iter = graph.find(geometry, Geo.AS_WKT_NODE, null); literalNode = extractObject(iter); } if (literalNode == null) { iter = graph.find(geometry, Geo.AS_GML_NODE, null); literalNode = extractObject(iter); } if (literalNode != null) { return new SpatialObjectGeometryLiteral(targetSpatialObject, literalNode); } } else { if (graph.contains(targetSpatialObject, SpatialExtension.GEO_LAT_NODE, null) && graph.contains(targetSpatialObject, SpatialExtension.GEO_LON_NODE, null)) { ExtendedIterator<Triple> latIter = graph.find(targetSpatialObject, SpatialExtension.GEO_LAT_NODE, null); Node lat = latIter.next().getObject(); ExtendedIterator<Triple> lonIter = graph.find(targetSpatialObject, SpatialExtension.GEO_LON_NODE, null); Node lon = lonIter.next().getObject(); if (latIter.hasNext() || lonIter.hasNext()) { latIter.close(); lonIter.close(); throw new DatatypeFormatException(targetSpatialObject.getURI() + " has more than one geo:lat or geo:lon property."); } Node latLonGeometryLiteral = ConvertLatLon.toNode(lat, lon); return new SpatialObjectGeometryLiteral(targetSpatialObject, latLonGeometryLiteral); } } return new SpatialObjectGeometryLiteral(null, null); } SpatialObjectGeometryLiteral(Node spatialObject, Node geometryLiteral); Node getSpatialObject(); Node getGeometryLiteral(); boolean isValid(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testRetrieve() { Graph graph = MODEL.getGraph(); Node targetSpatialObject = null; SpatialObjectGeometryLiteral instance = SpatialObjectGeometryLiteral.retrieve(graph, targetSpatialObject); boolean expResult = false; boolean result = instance.isValid(); assertEquals(expResult, result); }
@Test public void testRetrieveGeometryLiteral_geometry() { Graph graph = MODEL.getGraph(); Resource targetSpatialObject = GEOMETRY_B; SpatialObjectGeometryLiteral expResult = new SpatialObjectGeometryLiteral(GEOMETRY_B.asNode(), LITERAL_B.asNode()); SpatialObjectGeometryLiteral result = SpatialObjectGeometryLiteral.retrieve(graph, targetSpatialObject.asNode()); assertEquals(expResult, result); }
@Test public void testRetrieveGeometryLiteral_feature() { Resource targetSpatialObject = FEATURE_B; SpatialObjectGeometryLiteral expResult = new SpatialObjectGeometryLiteral(FEATURE_B.asNode(), LITERAL_B.asNode()); SpatialObjectGeometryLiteral result = SpatialObjectGeometryLiteral.retrieve(MODEL.getGraph(), targetSpatialObject.asNode()); assertEquals(expResult, result); }
@Test public void testRetrieveGeometryLiteral_feature_lat_lon() { Resource targetSpatialObject = GEO_FEATURE_Y; SpatialObjectGeometryLiteral expResult = new SpatialObjectGeometryLiteral(GEO_FEATURE_Y.asNode(), GEO_FEATURE_LITERAL.asNode()); SpatialObjectGeometryLiteral result = SpatialObjectGeometryLiteral.retrieve(MODEL.getGraph(), targetSpatialObject.asNode()); assertEquals(expResult, result); }
@Test(expected = DatatypeFormatException.class) public void testRetrieveGeometryLiteral_multiple_lat() { Model model = ModelFactory.createDefaultModel(); Resource feature = model.createResource("http: feature.addLiteral(SpatialExtension.GEO_LAT_PROP, ResourceFactory.createTypedLiteral("0.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LAT_PROP, ResourceFactory.createTypedLiteral("1.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LON_PROP, ResourceFactory.createTypedLiteral("60.0", XSDDatatype.XSDfloat)); SpatialObjectGeometryLiteral.retrieve(model.getGraph(), feature.asNode()); }
@Test(expected = DatatypeFormatException.class) public void testRetrieveGeometryLiteral_multiple_lon() { Model model = ModelFactory.createDefaultModel(); Resource feature = model.createResource("http: feature.addLiteral(SpatialExtension.GEO_LAT_PROP, ResourceFactory.createTypedLiteral("0.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LON_PROP, ResourceFactory.createTypedLiteral("60.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LON_PROP, ResourceFactory.createTypedLiteral("70.0", XSDDatatype.XSDfloat)); SpatialObjectGeometryLiteral.retrieve(model.getGraph(), feature.asNode()); }
@Test(expected = DatatypeFormatException.class) public void testRetrieveGeometryLiteral_multiple_lat_lon() { Model model = ModelFactory.createDefaultModel(); Resource feature = model.createResource("http: feature.addLiteral(SpatialExtension.GEO_LAT_PROP, ResourceFactory.createTypedLiteral("0.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LAT_PROP, ResourceFactory.createTypedLiteral("1.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LON_PROP, ResourceFactory.createTypedLiteral("60.0", XSDDatatype.XSDfloat)); feature.addLiteral(SpatialExtension.GEO_LON_PROP, ResourceFactory.createTypedLiteral("70.0", XSDDatatype.XSDfloat)); SpatialObjectGeometryLiteral.retrieve(model.getGraph(), feature.asNode()); }