Opened 4 years ago

#1056 new defect

GEOSClipByRect: Incorrect line clipping

Reported by: Algunenano Owned by: geos-devel@…
Priority: major Milestone: 3.8.2
Component: Default Version: 3.8.0
Severity: Unassigned Keywords:
Cc:

Description

Comes from Postgis' https://trac.osgeo.org/postgis/ticket/4765

There are some situations where parts of a line that matches the box boundaries are not included in the final intersection.

Example in GEOS itself:

diff --git a/tests/unit/capi/GEOSClipByRectTest.cpp b/tests/unit/capi/GEOSClipByRectTest.cpp
index e5358436..364c6649 100644
--- a/tests/unit/capi/GEOSClipByRectTest.cpp
+++ b/tests/unit/capi/GEOSClipByRectTest.cpp
@@ -200,5 +200,19 @@ template<> template<> void object::test<13>
     isEqual(geom2_, "POLYGON ((5 5, 5 15, 10 15, 10 10, 15 10, 15 5, 5 5))");
 }
 
+/// Comes from https://trac.osgeo.org/postgis/ticket/4765
+template<> template<> void object::test<14>
+()
+{
+    const char* wkt = "LINESTRING(0 0, 0 15, 15 15, 1 1)";
+    geom1_ = GEOSGeomFromWKT(wkt);
+    geom2_ = GEOSClipByRect(geom1_, 0, 0, 10, 10);
+    /*
+     * EXP: MULTILINESTRING((0 0,0 10),(10 10,1 1))
+     * OBT: LINESTRING (10 10, 1 1)
+     */
+    isEqual(geom2_, "MULTILINESTRING((0 0,0 10),(10 10,1 1))");
+}
+
 } // namespace tut
 

Broken in at least GEOS 3.8 and master (I haven't tested it in older releases).

Attaching an image showcasing the issue.

Attachments (1)

clipByBox.png (24.4 KB ) - added by Algunenano 4 years ago.

Download all attachments as: .zip

Change History (1)

by Algunenano, 4 years ago

Attachment: clipByBox.png added
Note: See TracTickets for help on using tickets.