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 70ec50c93b [SEDONA-698] Fix ST_RemoveRepeatedPoints (#1759)
70ec50c93b is described below

commit 70ec50c93b113c42c1f72712aff99d4452ce7107
Author: Furqaan Khan <[email protected]>
AuthorDate: Thu Jan 16 01:48:41 2025 -0500

    [SEDONA-698] Fix ST_RemoveRepeatedPoints (#1759)
---
 .../utils/GeometryDuplicateCoordinateRemover.java      |  2 +-
 .../java/org/apache/sedona/common/FunctionsTest.java   | 18 ++++++++++++++++++
 .../org/apache/sedona/sql/functionTestScala.scala      |  7 +++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/common/src/main/java/org/apache/sedona/common/utils/GeometryDuplicateCoordinateRemover.java
 
b/common/src/main/java/org/apache/sedona/common/utils/GeometryDuplicateCoordinateRemover.java
index 0838b75a3d..9f185d77fd 100644
--- 
a/common/src/main/java/org/apache/sedona/common/utils/GeometryDuplicateCoordinateRemover.java
+++ 
b/common/src/main/java/org/apache/sedona/common/utils/GeometryDuplicateCoordinateRemover.java
@@ -33,7 +33,7 @@ public class GeometryDuplicateCoordinateRemover {
 
     double distance = Double.MAX_VALUE;
 
-    if (numPoint <= minPoints) return new Coordinate[0];
+    if (numPoint < minPoints) return new Coordinate[0];
 
     Coordinate lastPoint = coords[0];
     int writeIndex = 1;
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 c34513e10d..38b5cb3035 100644
--- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
+++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
@@ -1854,6 +1854,24 @@ public class FunctionsTest extends TestBase {
     actual = Functions.asWKT(Functions.removeRepeatedPoints(geom, 2000));
     expected = "MULTIPOINT ((1 1))";
     assertEquals(expected, actual);
+
+    // The minimum number of coordinates in valid geometry shouldn't result in 
an empty geometry
+    geom = Constructors.geomFromWKT("POLYGON ((40 40, 70 70, 70 70, 40 40))", 
0);
+    actual = Functions.asWKT(Functions.removeRepeatedPoints(geom));
+    expected = "POLYGON ((40 40, 70 70, 70 70, 40 40))";
+    assertEquals(expected, actual);
+
+    geom =
+        Constructors.geomFromWKT(
+            "POLYGON ((40 40, 70 70, 70 70, 40 40), (40 40, 70 70, 50 50, 70 
70, 40 40))", 0);
+    actual = Functions.asWKT(Functions.removeRepeatedPoints(geom));
+    expected = "POLYGON ((40 40, 70 70, 70 70, 40 40), (40 40, 70 70, 50 50, 
70 70, 40 40))";
+    assertEquals(expected, actual);
+
+    geom = Constructors.geomFromWKT("LINESTRING(0 0, 1 1)", 0);
+    actual = Functions.asWKT(Functions.removeRepeatedPoints(geom));
+    expected = "LINESTRING (0 0, 1 1)";
+    assertEquals(expected, actual);
   }
 
   @Test
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala 
b/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
index 0e352b1e9e..d37cc3b648 100644
--- a/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
+++ b/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
@@ -1948,6 +1948,13 @@ class functionTestScala
       .get(0)
     expected = "LINESTRING (0 0, 5 5, 2 2)"
     assertEquals(expected, actual)
+
+    actual = sparkSession
+      .sql("SELECT ST_AsText(ST_RemoveRepeatedPoints(ST_GeomFromWKT('POLYGON 
((40 40, 70 70, 70 70, 40 40))')))")
+      .first()
+      .get(0)
+    expected = "POLYGON ((40 40, 70 70, 70 70, 40 40))"
+    assertEquals(expected, actual)
   }
 
   it("Should correctly set using ST_SetPoint") {

Reply via email to