LorenzBuehmann opened a new issue, #2219:
URL: https://github.com/apache/jena/issues/2219

   ### Version
   
   4.10.0 5.0.0-SNAPSHOT
   
   ### What happened?
   
   Calling the GeoSPARQL function `geof:sfIntersects` with e.g. 
`FILTER(geof:sfIntersects(?g1, ?g2))` can lead to an exception when the first 
geometry `g1`is an rectangle. See the following code to reproduce:
   
   ``` java
   package org.apache.jena.geosparql;
   
   import org.apache.jena.geosparql.implementation.GeometryWrapper;
   import org.apache.jena.geosparql.implementation.vocabulary.GeoSPARQL_URI;
   import org.apache.jena.graph.Node;
   import org.apache.jena.riot.system.PrefixMap;
   import org.apache.jena.riot.system.PrefixMapFactory;
   import org.apache.jena.sparql.util.NodeFactoryExtra;
   
   public class GeometryIntersectionBug {
   
       public static void main(String[] args) throws Exception {
           PrefixMap pm = PrefixMapFactory.create(GeoSPARQL_URI.getPrefixes());
   
           // a hexagon
           String polygonLitStr = "\"POLYGON ((10.0656923 55.3948787, 9.3745308 
53.9755137, 11.2451705 53.0320397, 13.8395286 53.4872452, 14.6402066 
54.9021819, 12.739823 55.8673267, 10.0656923 55.3948787))\"^^geo:wktLiteral";
           Node polygonNode = NodeFactoryExtra.parseNode(polygonLitStr, pm);
           GeometryWrapper polygonGeom = GeometryWrapper.extract(polygonNode);
   
           // a rectangle
           String rectangleLitStr = "\"POLYGON((6.2520337 47.7361897, 6.2520337 
53.7746148, 14.0584217 53.7746148, 14.0584217 47.7361897, 6.2520337 
47.7361897))\"^^geo:wktLiteral";
           Node rectangleNode = NodeFactoryExtra.parseNode(rectangleLitStr, pm);
           GeometryWrapper rectangleGeom = 
GeometryWrapper.extract(rectangleNode);
   
           // check if both geometries intersect
           boolean intersects1  = polygonGeom.intersects(rectangleGeom); // 
works
   
           boolean intersects2 = rectangleGeom.intersects(polygonGeom); // error
   
       }
   }
   ```
   It happens because the underlying JTS API does use an optimized algorithm 
for rectangles to terminate as early as possible. During this algorithm some 
new `Coordinate` objects will be created which make use of some Jena specific 
implementation which assumes not only XY geometries but also the Z axis. This 
results in an exception.
   
   ### Relevant output and stacktrace
   
   ```shell
   Exception in thread "main" java.lang.IllegalArgumentException: CoordinateXY 
dimension 2 does not support z-ordinate
        at org.locationtech.jts.geom.CoordinateXY.setZ(CoordinateXY.java:99)
        at 
org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence.getCoordinate(CustomCoordinateSequence.java:397)
        at 
org.locationtech.jts.operation.predicate.RectangleIntersectsSegmentVisitor.checkIntersectionWithSegments(RectangleIntersects.java:327)
        at 
org.locationtech.jts.operation.predicate.RectangleIntersectsSegmentVisitor.checkIntersectionWithLineStrings(RectangleIntersects.java:315)
        at 
org.locationtech.jts.operation.predicate.RectangleIntersectsSegmentVisitor.visit(RectangleIntersects.java:308)
        at 
org.locationtech.jts.geom.util.ShortCircuitedGeometryVisitor.applyTo(ShortCircuitedGeometryVisitor.java:35)
        at 
org.locationtech.jts.operation.predicate.RectangleIntersects.intersects(RectangleIntersects.java:110)
        at 
org.locationtech.jts.operation.predicate.RectangleIntersects.intersects(RectangleIntersects.java:58)
        at 
org.locationtech.jts.geom.prep.PreparedPolygon.intersects(PreparedPolygon.java:84)
        at 
org.apache.jena.geosparql.implementation.GeometryWrapper.intersects(GeometryWrapper.java:882)
        at 
org.apache.jena.geosparql.GeometryIntersectionBug.main(GeometryIntersectionBug.java:29)
   ```
   
   
   ### Are you interested in making a pull request?
   
   Maybe


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to