This is an automated email from the ASF dual-hosted git repository.

afs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit 1c77d8c01d38f9c158c8fe7f057ea39f76f6f6bd
Author: Thomas Thelen <[email protected]>
AuthorDate: Tue Jun 23 10:45:09 2026 -0700

    GH-3320 Use the generic distance function for generic distance computation 
routing
---
 .../filter_functions/DistanceFF.java               |  3 +-
 .../filter_functions/DistanceFFTest.java           | 35 +++++++++++++++++-----
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFF.java
 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFF.java
index 7cb4b801eb..05ba8def08 100644
--- 
a/jena-geosparql/src/main/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFF.java
+++ 
b/jena-geosparql/src/main/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFF.java
@@ -50,8 +50,7 @@ public class DistanceFF extends FunctionBase3 {
                 throw new ExprEvalException("Not a IRI: " + 
FmtUtils.stringForNode(v3.asNode()));
             }
 
-            //GeoSPARQL uses the Euclidean distance regardless of SRS URI.
-            double distance = geometry1.distanceEuclidean(geometry2, 
v3.asNode().getURI());
+            double distance = geometry1.distance(geometry2, 
v3.asNode().getURI());
 
             return NodeValue.makeDouble(distance);
         } catch (DatatypeFormatException ex) {
diff --git 
a/jena-geosparql/src/test/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFFTest.java
 
b/jena-geosparql/src/test/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFFTest.java
index 51a58a088f..7da75e4e70 100644
--- 
a/jena-geosparql/src/test/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFFTest.java
+++ 
b/jena-geosparql/src/test/java/org/apache/jena/geosparql/geof/nontopological/filter_functions/DistanceFFTest.java
@@ -87,31 +87,50 @@ public class DistanceFFTest {
     }
 
     /**
-     * Test of exec method, of class DistanceFF.
+     * Geographic SRS with angular units throws because great circle distance 
only supports linear units.
      */
-    @Test
-    public void testExec_geographic_radians() {
+    @Test(expected = ExprEvalException.class)
+    public void testExec_geographic_radians_exception() {
 
         NodeValue v1 = NodeValue.makeNode("Point(11.41 53.63)", 
WKTDatatype.INSTANCE);
         NodeValue v2 = NodeValue.makeNode("Point(11.57 48.13)", 
WKTDatatype.INSTANCE);
         NodeValue v3 = 
NodeValue.makeNode(NodeFactory.createURI(Unit_URI.RADIAN_URL));
         DistanceFF instance = new DistanceFF();
-        double expResult = 0.096034;
         double result = instance.exec(v1, v2, v3).getDouble();
-        assertEquals(expResult, result, 0.0001);
     }
 
     /**
      * Test of exec method, of class DistanceFF.
+     * Geographic SRS (CRS84 default WKT) with linear units should use great 
circle distance,
+     * as per GeoSPARQL 1.1
      */
-    @Test(expected = ExprEvalException.class)
-    public void testExec_geographic_metres_exception() {
+    @Test
+    public void testExec_geographic_kilometres() {
 
         NodeValue v1 = NodeValue.makeNode("Point(11.41 53.63)", 
WKTDatatype.INSTANCE);
         NodeValue v2 = NodeValue.makeNode("Point(11.57 48.13)", 
WKTDatatype.INSTANCE);
         NodeValue v3 = 
NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETRE_URN));
         DistanceFF instance = new DistanceFF();
+        double expResult = 611.6755;
+        double result = instance.exec(v1, v2, v3).getDouble();
+        assertEquals(expResult, result, 0.0001);
+    }
+
+    /**
+     * Test of exec method, of class DistanceFF.
+     * Geographic SRS (EPSG:4326) with linear units should use great circle 
distance,
+     * as per GeoSPARQL 1.1.
+     */
+    @Test
+    public void testExec_geographic_kilometres_epsg4326() {
+
+        NodeValue v1 = 
NodeValue.makeNode("<http://www.opengis.net/def/crs/EPSG/0/4326> POINT(10.0 
20.0)", WKTDatatype.INSTANCE);
+        NodeValue v2 = 
NodeValue.makeNode("<http://www.opengis.net/def/crs/EPSG/0/4326> POINT(10.0 
21.0)", WKTDatatype.INSTANCE);
+        NodeValue v3 = 
NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETRE_URN));
+        DistanceFF instance = new DistanceFF();
+        double expResult = 109.5057;
         double result = instance.exec(v1, v2, v3).getDouble();
+        assertEquals(expResult, result, 0.0001);
     }
 
     /**
@@ -139,7 +158,7 @@ public class DistanceFFTest {
      */
     @Test(expected = ExprEvalException.class)
     public void testExec_conversion_exception_units() {
-        // Still receive an expection as the units of v1 and v3 don't align.
+        // Still receive an exception: SRS transform disabled, so geographic 
v1 cannot transform projected v2.
         GeoSPARQLConfig.allowGeometrySRSTransformation(false);     // Disable 
default config.
         NodeValue v1 = NodeValue.makeNode("Point(11.57 48.13)", 
WKTDatatype.INSTANCE);
         NodeValue v2 = 
NodeValue.makeNode("<http://www.opengis.net/def/crs/EPSG/0/27700> POINT(90 
60)", WKTDatatype.INSTANCE);

Reply via email to