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 0a8b82d17 [SEDONA-658] Add ST_Simplify (#1606)
0a8b82d17 is described below
commit 0a8b82d17fc0b43721a12f32e15ecb689e334546
Author: Furqaan Khan <[email protected]>
AuthorDate: Thu Sep 26 20:46:56 2024 -0400
[SEDONA-658] Add ST_Simplify (#1606)
* feat: Add ST_Simplify
* fix: snowflake tests
* docs: fix formatting
---
.../java/org/apache/sedona/common/Functions.java | 5 +++++
.../org/apache/sedona/common/FunctionsTest.java | 23 ++++++++++++++++++++++
docs/api/flink/Function.md | 23 ++++++++++++++++++++++
docs/api/snowflake/vector-data/Function.md | 21 ++++++++++++++++++++
docs/api/sql/Function.md | 23 ++++++++++++++++++++++
.../main/java/org/apache/sedona/flink/Catalog.java | 1 +
.../apache/sedona/flink/expressions/Functions.java | 10 ++++++++++
.../java/org/apache/sedona/flink/FunctionTest.java | 11 +++++++++++
python/sedona/sql/st_functions.py | 16 +++++++++++++++
python/tests/sql/test_dataframe_api.py | 9 +++++++++
python/tests/sql/test_function.py | 8 ++++++++
.../sedona/snowflake/snowsql/TestFunctions.java | 10 ++++++++++
.../sedona/snowflake/snowsql/TestFunctionsV2.java | 10 ++++++++++
.../org/apache/sedona/snowflake/snowsql/UDFs.java | 6 ++++++
.../apache/sedona/snowflake/snowsql/UDFsV2.java | 9 +++++++++
.../scala/org/apache/sedona/sql/UDF/Catalog.scala | 1 +
.../sql/sedona_sql/expressions/Functions.scala | 8 ++++++++
.../sql/sedona_sql/expressions/st_functions.scala | 5 +++++
.../org/apache/sedona/sql/PreserveSRIDSuite.scala | 1 +
.../apache/sedona/sql/dataFrameAPITestScala.scala | 7 +++++++
.../org/apache/sedona/sql/functionTestScala.scala | 7 +++++++
21 files changed, 214 insertions(+)
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 038bfeebe..430071a04 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -60,6 +60,7 @@ import org.locationtech.jts.operation.valid.IsValidOp;
import org.locationtech.jts.operation.valid.TopologyValidationError;
import org.locationtech.jts.precision.GeometryPrecisionReducer;
import org.locationtech.jts.precision.MinimumClearance;
+import org.locationtech.jts.simplify.DouglasPeuckerSimplifier;
import org.locationtech.jts.simplify.PolygonHullSimplifier;
import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
import org.locationtech.jts.simplify.VWSimplifier;
@@ -1543,6 +1544,10 @@ public class Functions {
return polygons.toArray(new Polygon[0]);
}
+ public static Geometry simplify(Geometry geom, double distanceTolerance) {
+ return DouglasPeuckerSimplifier.simplify(geom, distanceTolerance);
+ }
+
// create static function named simplifyPreserveTopology
public static Geometry simplifyPreserveTopology(Geometry geometry, double
distanceTolerance) {
return TopologyPreservingSimplifier.simplify(geometry, distanceTolerance);
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 dbec7c651..a4feca5f0 100644
--- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
+++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
@@ -1790,6 +1790,29 @@ public class FunctionsTest extends TestBase {
assertEquals(6000, actualSRID);
}
+ @Test
+ public void simplify() throws ParseException {
+ Geometry geom = Constructors.geomFromWKT("POINT (1 2)", 1111);
+ geom = Functions.buffer(geom, 10, false, "quad_segs=12");
+ int actualPoints = Functions.nPoints(Functions.simplify(geom, 0.1));
+ int expectedPoints = 33;
+ assertEquals(expectedPoints, actualPoints);
+
+ actualPoints = Functions.nPoints(Functions.simplify(geom, 0.5));
+ expectedPoints = 17;
+ assertEquals(expectedPoints, actualPoints);
+
+ actualPoints = Functions.nPoints(Functions.simplify(geom, 1));
+ expectedPoints = 9;
+ assertEquals(expectedPoints, actualPoints);
+
+ Geometry actual = Functions.simplify(geom, 10);
+ actualPoints = Functions.nPoints(actual);
+ expectedPoints = 4;
+ assertEquals(expectedPoints, actualPoints);
+ assertEquals(1111, actual.getSRID());
+ }
+
@Test
public void simplifyVW() throws ParseException {
Geometry geom = Constructors.geomFromEWKT("LINESTRING(5 2, 3 8, 6 20, 7
25, 10 10)");
diff --git a/docs/api/flink/Function.md b/docs/api/flink/Function.md
index 82444ad31..2fcfaa8d0 100644
--- a/docs/api/flink/Function.md
+++ b/docs/api/flink/Function.md
@@ -3513,6 +3513,29 @@ Output:
3021
```
+## ST_Simplify
+
+Introduction: This function simplifies the input geometry by applying the
Douglas-Peucker algorithm.
+
+!!!Note
+ The simplification may not preserve topology, potentially producing
invalid geometries. Use
[ST_SimplifyPreserveTopology](#st_simplifypreservetopology) to retain valid
topology after simplification.
+
+Format: `ST_Simplify(geom: Geometry, tolerance: Double)`
+
+Since: `v1.7.0`
+
+SQL Example:
+
+```sql
+SELECT ST_Simplify(ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10), 1)
+```
+
+Output:
+
+```
+POLYGON ((10 2, 7.0710678118654755 -5.071067811865475, 0.0000000000000006 -8,
-7.071067811865475 -5.0710678118654755, -10 1.9999999999999987,
-7.071067811865477 9.071067811865476, -0.0000000000000018 12, 7.071067811865474
9.071067811865477, 10 2))
+```
+
## ST_SimplifyPolygonHull
Introduction: This function computes a topology-preserving simplified hull,
either outer or inner, for a polygonal geometry input. An outer hull fully
encloses the original geometry, while an inner hull lies entirely within. The
result maintains the same structure as the input, including handling of
MultiPolygons and holes, represented as a polygonal geometry formed from a
subset of vertices.
diff --git a/docs/api/snowflake/vector-data/Function.md
b/docs/api/snowflake/vector-data/Function.md
index 671588c99..8412f2e3b 100644
--- a/docs/api/snowflake/vector-data/Function.md
+++ b/docs/api/snowflake/vector-data/Function.md
@@ -2698,6 +2698,27 @@ Output:
LINESTRING(177 10, 179 10, 181 10, 183 10)
```
+## ST_Simplify
+
+Introduction: This function simplifies the input geometry by applying the
Douglas-Peucker algorithm.
+
+!!!Note
+ The simplification may not preserve topology, potentially producing
invalid geometries. Use
[ST_SimplifyPreserveTopology](#st_simplifypreservetopology) to retain valid
topology after simplification.
+
+Format: `ST_Simplify(geom: Geometry, tolerance: Double)`
+
+SQL Example:
+
+```sql
+SELECT ST_Simplify(ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10), 1)
+```
+
+Output:
+
+```
+POLYGON ((10 2, 7.0710678118654755 -5.071067811865475, 0.0000000000000006 -8,
-7.071067811865475 -5.0710678118654755, -10 1.9999999999999987,
-7.071067811865477 9.071067811865476, -0.0000000000000018 12, 7.071067811865474
9.071067811865477, 10 2))
+```
+
## ST_SimplifyPolygonHull
Introduction: This function computes a topology-preserving simplified hull,
either outer or inner, for a polygonal geometry input. An outer hull fully
encloses the original geometry, while an inner hull lies entirely within. The
result maintains the same structure as the input, including handling of
MultiPolygons and holes, represented as a polygonal geometry formed from a
subset of vertices.
diff --git a/docs/api/sql/Function.md b/docs/api/sql/Function.md
index bac772713..6410112e3 100644
--- a/docs/api/sql/Function.md
+++ b/docs/api/sql/Function.md
@@ -3573,6 +3573,29 @@ Output:
LINESTRING(177 10, 179 10, 181 10, 183 10)
```
+## ST_Simplify
+
+Introduction: This function simplifies the input geometry by applying the
Douglas-Peucker algorithm.
+
+!!!Note
+ The simplification may not preserve topology, potentially producing
invalid geometries. Use
[ST_SimplifyPreserveTopology](#st_simplifypreservetopology) to retain valid
topology after simplification.
+
+Format: `ST_Simplify(geom: Geometry, tolerance: Double)`
+
+Since: `v1.7.0`
+
+SQL Example:
+
+```sql
+SELECT ST_Simplify(ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10), 1)
+```
+
+Output:
+
+```
+POLYGON ((10 2, 7.0710678118654755 -5.071067811865475, 0.0000000000000006 -8,
-7.071067811865475 -5.0710678118654755, -10 1.9999999999999987,
-7.071067811865477 9.071067811865476, -0.0000000000000018 12, 7.071067811865474
9.071067811865477, 10 2))
+```
+
## ST_SimplifyPolygonHull
Introduction: This function computes a topology-preserving simplified hull,
either outer or inner, for a polygonal geometry input. An outer hull fully
encloses the original geometry, while an inner hull lies entirely within. The
result maintains the same structure as the input, including handling of
MultiPolygons and holes, represented as a polygonal geometry formed from a
subset of vertices.
diff --git a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
index 82b8cbc4c..bef646521 100644
--- a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
+++ b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
@@ -172,6 +172,7 @@ public class Catalog {
new Functions.ST_Multi(),
new Functions.ST_StartPoint(),
new Functions.ST_ShiftLongitude(),
+ new Functions.ST_Simplify(),
new Functions.ST_SimplifyPreserveTopology(),
new Functions.ST_SimplifyVW(),
new Functions.ST_SimplifyPolygonHull(),
diff --git
a/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
b/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
index 85f634083..ccaefc218 100644
--- a/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
+++ b/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
@@ -1394,6 +1394,16 @@ public class Functions {
}
}
+ public static class ST_Simplify extends ScalarFunction {
+ @DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class)
+ public Geometry eval(
+ @DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class) Object o,
+ @DataTypeHint("Double") Double distanceTolerance) {
+ Geometry geom = (Geometry) o;
+ return org.apache.sedona.common.Functions.simplify(geom,
distanceTolerance);
+ }
+ }
+
public static class ST_SimplifyPreserveTopology extends ScalarFunction {
@DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class)
public Geometry eval(
diff --git a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
index ccbb586f6..4de98c0fd 100644
--- a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
@@ -1739,6 +1739,17 @@ public class FunctionTest extends TestBase {
assertEquals("POINT (0 0)", result.toString());
}
+ @Test
+ public void testSimplify() {
+ Table table = tableEnv.sqlQuery("SELECT ST_Buffer(ST_GeomFromWKT('POINT (0
2)'), 10) AS geom");
+ Geometry actualGeometry =
+ (Geometry)
+
first(table.select(call(Functions.ST_Simplify.class.getSimpleName(), $("geom"),
1)))
+ .getField(0);
+ int actualPoints = actualGeometry.getNumPoints();
+ assertEquals(9, actualPoints);
+ }
+
@Test
public void testSimplifyPreserveTopology() {
Table table =
diff --git a/python/sedona/sql/st_functions.py
b/python/sedona/sql/st_functions.py
index e37ab4b56..16ff25a3e 100644
--- a/python/sedona/sql/st_functions.py
+++ b/python/sedona/sql/st_functions.py
@@ -1666,6 +1666,22 @@ def ST_SubDivideExplode(
return _call_st_function("ST_SubDivideExplode", (geometry, max_vertices))
+@validate_argument_types
+def ST_Simplify(
+ geometry: ColumnOrName, distance_tolerance: ColumnOrNameOrNumber
+) -> Column:
+ """Simplify a geometry using Douglas-Peucker algorithm within a specified
tolerance while preserving topological relationships.
+
+ :param geometry: Geometry column to simplify.
+ :type geometry: ColumnOrName
+ :param distance_tolerance: Tolerance for merging points together to
simplify the geometry as either a number or numeric column.
+ :type distance_tolerance: ColumnOrNameOrNumber
+ :return: Simplified geometry as a geometry column.
+ :rtype: Column
+ """
+ return _call_st_function("ST_Simplify", (geometry, distance_tolerance))
+
+
@validate_argument_types
def ST_SimplifyPreserveTopology(
geometry: ColumnOrName, distance_tolerance: ColumnOrNameOrNumber
diff --git a/python/tests/sql/test_dataframe_api.py
b/python/tests/sql/test_dataframe_api.py
index 223bfc840..c3e4d208c 100644
--- a/python/tests/sql/test_dataframe_api.py
+++ b/python/tests/sql/test_dataframe_api.py
@@ -900,6 +900,13 @@ test_configurations = [
"",
"POLYGON ((0 0, 1 0, 1 1, 0 0))",
),
+ (
+ stf.ST_Simplify,
+ ("geom", 0.1),
+ "0.9_poly",
+ "",
+ "POLYGON ((0 0, 1 0, 1 1, 0 0))",
+ ),
(
stf.ST_SimplifyPreserveTopology,
("geom", 0.2),
@@ -1330,6 +1337,8 @@ wrong_type_configurations = [
(stf.ST_SetSRID, ("", None)),
(stf.ST_SetSRID, ("", 3021.0)),
(stf.ST_ShiftLongitude, (None,)),
+ (stf.ST_Simplify, (None, 2)),
+ (stf.ST_Simplify, ("", None)),
(stf.ST_SimplifyPreserveTopology, (None, 0.2)),
(stf.ST_SimplifyPreserveTopology, ("", None)),
(stf.ST_SimplifyVW, (None, 2)),
diff --git a/python/tests/sql/test_function.py
b/python/tests/sql/test_function.py
index 028b4faac..5b61d3600 100644
--- a/python/tests/sql/test_function.py
+++ b/python/tests/sql/test_function.py
@@ -1442,6 +1442,14 @@ class TestPredicateJoin(TestBase):
).take(1)[0][0]
assert actual
+ def test_st_simplify(self):
+ baseDf = self.spark.sql(
+ "SELECT ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10) AS geom"
+ )
+ actualPoints = baseDf.selectExpr("ST_NPoints(ST_Simplify(geom,
1))").first()[0]
+ expectedPoints = 9
+ assert expectedPoints == actualPoints
+
def test_st_simplify_vw(self):
basedf = self.spark.sql(
"SELECT ST_GeomFromWKT('LINESTRING(5 2, 3 8, 6 20, 7 25, 10 10)')
as geom"
diff --git
a/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctions.java
b/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctions.java
index 79c5843ef..ae970d591 100644
---
a/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctions.java
+++
b/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctions.java
@@ -877,6 +877,16 @@ public class TestFunctions extends TestBase {
"SRID=4326;POINT (1 2)");
}
+ @Test
+ public void test_ST_Simplify() {
+ registerUDF("ST_Simplify", byte[].class, double.class);
+ registerUDF("ST_Buffer", byte[].class, double.class);
+ registerUDF("ST_NPoints", byte[].class);
+ verifySqlSingleRes(
+ "SELECT
sedona.ST_NPoints(sedona.ST_Simplify(sedona.ST_Buffer(sedona.ST_GeomFromWKT('POINT
(0 2)'), 10), 1))",
+ 9);
+ }
+
@Test
public void test_ST_SimplifyPreserveTopology() {
registerUDF("ST_SimplifyPreserveTopology", byte[].class, double.class);
diff --git
a/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctionsV2.java
b/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctionsV2.java
index d1941ea70..f64d44595 100644
---
a/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctionsV2.java
+++
b/snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctionsV2.java
@@ -838,6 +838,16 @@ public class TestFunctionsV2 extends TestBase {
"SRID=0;POINT(1 2)");
}
+ @Test
+ public void test_ST_Simplify() {
+ registerUDFV2("ST_Simplify", String.class, double.class);
+ registerUDFV2("ST_Buffer", String.class, double.class);
+ registerUDFV2("ST_NPoints", String.class);
+ verifySqlSingleRes(
+ "SELECT
sedona.ST_NPoints(sedona.ST_Simplify(sedona.ST_Buffer(ST_GeomFromWKT('POINT (0
2)'), 10), 1))",
+ 9);
+ }
+
@Test
public void test_ST_SimplifyPreserveTopology() {
registerUDFV2("ST_SimplifyPreserveTopology", String.class, double.class);
diff --git
a/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFs.java
b/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFs.java
index 40cd2585b..761204ab6 100644
--- a/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFs.java
+++ b/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFs.java
@@ -967,6 +967,12 @@ public class UDFs {
return
GeometrySerde.serialize(Functions.setSRID(GeometrySerde.deserialize(geometry),
srid));
}
+ @UDFAnnotations.ParamMeta(argNames = {"geometry", "distanceTolerance"})
+ public static byte[] ST_Simplify(byte[] geometry, double distanceTolerance) {
+ return GeometrySerde.serialize(
+ Functions.simplify(GeometrySerde.deserialize(geometry),
distanceTolerance));
+ }
+
@UDFAnnotations.ParamMeta(argNames = {"geometry", "distanceTolerance"})
public static byte[] ST_SimplifyPreserveTopology(byte[] geometry, double
distanceTolerance) {
return GeometrySerde.serialize(
diff --git
a/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFsV2.java
b/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFsV2.java
index f0c43981d..17c099eab 100644
--- a/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFsV2.java
+++ b/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/UDFsV2.java
@@ -1090,6 +1090,15 @@ public class UDFsV2 {
return
GeometrySerde.serGeoJson(Functions.setSRID(GeometrySerde.deserGeoJson(geometry),
srid));
}
+ @UDFAnnotations.ParamMeta(
+ argNames = {"geometry", "distanceTolerance"},
+ argTypes = {"Geometry", "double"},
+ returnTypes = "Geometry")
+ public static String ST_Simplify(String geometry, double distanceTolerance) {
+ return GeometrySerde.serGeoJson(
+ Functions.simplify(GeometrySerde.deserGeoJson(geometry),
distanceTolerance));
+ }
+
@UDFAnnotations.ParamMeta(
argNames = {"geometry", "distanceTolerance"},
argTypes = {"Geometry", "double"},
diff --git
a/spark/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
b/spark/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
index 2c0693110..6978b5162 100644
--- a/spark/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
+++ b/spark/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
@@ -116,6 +116,7 @@ object Catalog {
function[ST_AsHEXEWKB](),
function[ST_AsGML](),
function[ST_AsKML](),
+ function[ST_Simplify](),
function[ST_SimplifyVW](),
function[ST_SimplifyPolygonHull](),
function[ST_SRID](),
diff --git
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
index e309dcc7f..725796ee6 100644
---
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
+++
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
@@ -442,6 +442,14 @@ case class ST_ReducePrecision(inputExpressions:
Seq[Expression])
}
}
+case class ST_Simplify(inputExpressions: Seq[Expression])
+ extends InferredExpression(Functions.simplify _) {
+
+ protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) =
{
+ copy(inputExpressions = newChildren)
+ }
+}
+
case class ST_SimplifyVW(inputExpressions: Seq[Expression])
extends InferredExpression(Functions.simplifyVW _) {
diff --git
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
index 4699f43ff..da49f0143 100644
---
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
+++
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
@@ -596,6 +596,11 @@ object st_functions extends DataFrameAPI {
def ST_Transform(geometry: Column, targetCRS: Column): Column =
wrapExpression[ST_Transform](geometry, targetCRS)
+ def ST_Simplify(geometry: Column, distanceTolerance: Column): Column =
+ wrapExpression[ST_Simplify](geometry, distanceTolerance)
+ def ST_Simplify(geometry: String, distanceTolerance: Double): Column =
+ wrapExpression[ST_Simplify](geometry, distanceTolerance)
+
def ST_SimplifyVW(geometry: Column, distanceTolerance: Column): Column =
wrapExpression[ST_SimplifyVW](geometry, distanceTolerance)
def ST_SimplifyVW(geometry: String, distanceTolerance: Double): Column =
diff --git
a/spark/common/src/test/scala/org/apache/sedona/sql/PreserveSRIDSuite.scala
b/spark/common/src/test/scala/org/apache/sedona/sql/PreserveSRIDSuite.scala
index 17c0f2e98..c67525427 100644
--- a/spark/common/src/test/scala/org/apache/sedona/sql/PreserveSRIDSuite.scala
+++ b/spark/common/src/test/scala/org/apache/sedona/sql/PreserveSRIDSuite.scala
@@ -50,6 +50,7 @@ class PreserveSRIDSuite extends TestBaseScala with
TableDrivenPropertyChecks {
("ST_Intersection(geom1, ST_Point(0, 1))", 1000),
("ST_MakeValid(geom1)", 1000),
("ST_ReducePrecision(geom1, 6)", 1000),
+ ("ST_Simplify(geom1, 0.1)", 1000),
("ST_SimplifyVW(geom1, 0.1)", 1000),
("ST_SimplifyPolygonHull(geom1, 0.5)", 1000),
("ST_SetSRID(geom1, 2000)", 2000),
diff --git
a/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
b/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
index 981f88fd5..57e721979 100644
---
a/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
+++
b/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
@@ -900,6 +900,13 @@ class dataFrameAPITestScala extends TestBaseScala {
assert(actualResult == expectedResult)
}
+ it("Passed ST_Simplify") {
+ val baseDf = sparkSession.sql("SELECT ST_Buffer(ST_GeomFromWKT('POINT (0
2)'), 10) AS geom")
+ val actualPoints = baseDf.select(ST_NPoints(ST_Simplify("geom",
1))).first().get(0)
+ val expectedPoints = 9
+ assertEquals(expectedPoints, actualPoints)
+ }
+
it("Passed ST_SimplifyVW") {
val baseDf = sparkSession.sql(
"SELECT ST_GeomFromWKT('LINESTRING(5 2, 3 8, 6 20, 7 25, 10 10)') AS
geom")
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 fa83fbf78..f3c5796e3 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
@@ -884,6 +884,13 @@ class functionTestScala
assert(Hex.encodeHexString(df.first().get(0).asInstanceOf[Array[Byte]])
== s)
}
+ it("Passed ST_Simplify") {
+ val baseDf = sparkSession.sql("SELECT ST_Buffer(ST_GeomFromWKT('POINT (0
2)'), 10) AS geom")
+ val actualPoints = baseDf.selectExpr("ST_NPoints(ST_Simplify(geom,
1))").first().get(0)
+ val expectedPoints = 9
+ assertEquals(expectedPoints, actualPoints)
+ }
+
it("Passed ST_SimplifyVW") {
val baseDf = sparkSession.sql(
"SELECT ST_GeomFromWKT('LINESTRING(5 2, 3 8, 6 20, 7 25, 10 10)') AS
geom")