You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/02/19 12:48:39 UTC

[GitHub] [jena] afs commented on a change in pull request #692: GeoSPARQL: Malformed geo:lat and geo:lon checks

afs commented on a change in pull request #692: GeoSPARQL: Malformed geo:lat and geo:lon checks
URL: https://github.com/apache/jena/pull/692#discussion_r381268816
 
 

 ##########
 File path: jena-geosparql/src/main/java/org/apache/jena/geosparql/geo/topological/SpatialObjectGeometryLiteral.java
 ##########
 @@ -132,8 +133,22 @@ protected static final SpatialObjectGeometryLiteral retrieve(Graph graph, Node t
         } else {
             //Target is not a Feature or Geometry but could have Geo Predicates.
             if (graph.contains(targetSpatialObject, SpatialExtension.GEO_LAT_NODE, null) && graph.contains(targetSpatialObject, SpatialExtension.GEO_LON_NODE, null)) {
-                Node lat = graph.find(targetSpatialObject, SpatialExtension.GEO_LAT_NODE, null).next().getObject();
-                Node lon = graph.find(targetSpatialObject, SpatialExtension.GEO_LON_NODE, null).next().getObject();
+
+                //Extract Lat coordinate.
+                ExtendedIterator<Triple> latIter = graph.find(targetSpatialObject, SpatialExtension.GEO_LAT_NODE, null);
+                Node lat = latIter.next().getObject();
+
+                //Extract Lon coordinate.
+                ExtendedIterator<Triple> lonIter = graph.find(targetSpatialObject, SpatialExtension.GEO_LON_NODE, null);
+                Node lon = lonIter.next().getObject();
+
+                //Ensure that only a single Latitude and Longitude are present for the subject.
+                if (latIter.hasNext() || lonIter.hasNext()) {
+                    latIter.close();
+                    lonIter.close();
+                    throw new DatatypeFormatException(targetSpatialObject.getURI() + " has more than one geo:lat or geo:lon property.");
+                }
+
 
 Review comment:
   Sorry to be late to the game. 
   
   A comment: a useful pattern is 
   
       ExtendedIterator<> iter = ...;
       try { 
          ... process ...
       } finally { iter.close(); }
   
   There is no harm calling close multiple times or on already closed iterators.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org