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

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new ff6a0df1bc [GH-2403] SetSRID handle empty geometry types (#2615)
ff6a0df1bc is described below

commit ff6a0df1bc07be3990d7afc56e8bffd38f1a0504
Author: Jia Yu <[email protected]>
AuthorDate: Sat Feb 7 12:16:42 2026 -0700

    [GH-2403] SetSRID handle empty geometry types (#2615)
---
 .../java/org/apache/sedona/common/Functions.java     |  7 ++++++-
 .../java/org/apache/sedona/common/FunctionsTest.java | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/common/src/main/java/org/apache/sedona/common/Functions.java 
b/common/src/main/java/org/apache/sedona/common/Functions.java
index b593a82065..0ade0e66a1 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -923,7 +923,12 @@ public class Functions {
             geometry.getPrecisionModel(),
             srid,
             geometry.getFactory().getCoordinateSequenceFactory());
-    return factory.createGeometry(geometry);
+    Geometry newGeom = factory.createGeometry(geometry);
+    // Workaround for JTS bug: GeometryEditor.editPolygon returns the original
+    // empty polygon without copying it to the new factory, so the SRID is not
+    // updated for POLYGON EMPTY (and similar empty geometry types).
+    newGeom.setSRID(srid);
+    return newGeom;
   }
 
   public static int getSRID(Geometry geometry) {
diff --git a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java 
b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
index b90a53b708..c2aeced939 100644
--- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
+++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
@@ -4014,6 +4014,26 @@ public class FunctionsTest extends TestBase {
         
Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createGeometryCollection()));
   }
 
+  @Test
+  public void setSRIDEmptyGeometries() throws ParseException {
+    // Regression test for GH-2403: SetSRID doesn't work on POLYGON EMPTY
+    String[] emptyWkts = {
+      "POINT EMPTY",
+      "LINESTRING EMPTY",
+      "POLYGON EMPTY",
+      "MULTIPOINT EMPTY",
+      "MULTILINESTRING EMPTY",
+      "MULTIPOLYGON EMPTY",
+      "GEOMETRYCOLLECTION EMPTY"
+    };
+    for (String wkt : emptyWkts) {
+      Geometry geom = Constructors.geomFromWKT(wkt, 0);
+      Geometry result = Functions.setSRID(geom, 4236);
+      assertEquals("SRID should be set for " + wkt, 4236, result.getSRID());
+      assertTrue("Result should be empty for " + wkt, result.isEmpty());
+    }
+  }
+
   @Test
   public void closestPoint() {
     Point point1 = GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1));

Reply via email to