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 467f7ab7 [SEDONA-303] Port all Sedona Spark functions to Sedona Flink
-- Step 4 (#887)
467f7ab7 is described below
commit 467f7ab72bccb2f8b2c436b34f56fdbbe4469072
Author: Junhao Liu <[email protected]>
AuthorDate: Sat Jul 8 11:33:41 2023 +0800
[SEDONA-303] Port all Sedona Spark functions to Sedona Flink -- Step 4
(#887)
---
R/R/dependencies.R | 4 +--
R/tests/testthat/test-dbplyr-integration.R | 4 +--
docs/api/flink/Function.md | 29 ++++++++++++++++++++++
docs/api/sql/Function.md | 10 ++++----
.../main/java/org/apache/sedona/flink/Catalog.java | 2 ++
.../apache/sedona/flink/expressions/Functions.java | 26 ++++++++++++++++++-
.../java/org/apache/sedona/flink/FunctionTest.java | 29 ++++++++++++++++++++++
python/sedona/sql/st_functions.py | 6 ++---
python/tests/sql/test_dataframe_api.py | 22 ++++++++--------
python/tests/sql/test_function.py | 4 +--
.../streaming/spark/test_constructor_functions.py | 11 +++-----
.../scala/org/apache/sedona/sql/UDF/Catalog.scala | 4 +--
.../sql/sedona_sql/expressions/Functions.scala | 2 +-
.../sql/sedona_sql/expressions/st_functions.scala | 8 +++---
.../apache/sedona/sql/dataFrameAPITestScala.scala | 17 +++++++------
.../org/apache/sedona/sql/functionTestScala.scala | 10 ++++----
16 files changed, 134 insertions(+), 54 deletions(-)
diff --git a/R/R/dependencies.R b/R/R/dependencies.R
index fc38e848..ebf7a736 100644
--- a/R/R/dependencies.R
+++ b/R/R/dependencies.R
@@ -139,9 +139,9 @@ sedona_dbplyr_sql_variant <- function() {
"ST_Buffer(", geometry, ", CAST(", buffer, " AS DOUBLE))"
)
},
- ST_PrecisionReduce = function(geometry, precision) {
+ ST_ReducePrecision = function(geometry, precision) {
dbplyr::build_sql(
- "ST_PrecisionReduce(", geometry, ", CAST(", precision, " AS
INTEGER))"
+ "ST_ReducePrecision(", geometry, ", CAST(", precision, " AS
INTEGER))"
)
},
ST_SimplifyPreserveTopology = function(geometry, distance_tolerance) {
diff --git a/R/tests/testthat/test-dbplyr-integration.R
b/R/tests/testthat/test-dbplyr-integration.R
index 075fcf3f..3bae746e 100644
--- a/R/tests/testthat/test-dbplyr-integration.R
+++ b/R/tests/testthat/test-dbplyr-integration.R
@@ -77,10 +77,10 @@ test_that("ST_Buffer() works as expected", {
)
})
-test_that("ST_PrecisionReduce() works as expected", {
+test_that("ST_ReducePrecision() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(rectangle = ST_PolygonFromEnvelope(-40.12345678,
-30.12345678, 40.11111111, 30.11111111)) %>%
- dplyr::mutate(rectangle = ST_PrecisionReduce(rectangle, 2)) %>%
+ dplyr::mutate(rectangle = ST_ReducePrecision(rectangle, 2)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202
is
# fixed
sdf_register(name = random_string())
diff --git a/docs/api/flink/Function.md b/docs/api/flink/Function.md
index 884bed47..0ad9c628 100644
--- a/docs/api/flink/Function.md
+++ b/docs/api/flink/Function.md
@@ -1244,6 +1244,19 @@ Result:
+------------------+------------------------+
```
+## ST_MinimumBoundingCircle
+
+Introduction: Returns the smallest circle polygon that contains a geometry.
The optional quadrantSegments parameter determines how many segments to use per
quadrant and the default number of segments is 48.
+
+Format: `ST_MinimumBoundingCircle(geom: geometry, [Optional]
quadrantSegments:int)`
+
+Since: `v1.5.0`
+
+Example:
+```sql
+SELECT ST_MinimumBoundingCircle(ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1
1))'))
+
+
## ST_Multi
Introduction: Returns a MultiGeometry object based on the geometry input.
@@ -1480,6 +1493,22 @@ FROM df
Output: `POINT Z(0 0 1)`
+## ST_ReducePrecision
+
+Introduction: Reduce the decimals places in the coordinates of the geometry to
the given number of decimal places. The last decimal place will be rounded.
+
+Format: `ST_ReducePrecision (A:geometry, B:int)`
+
+Since: `v1.5.0`
+
+Example:
+
+```sql
+SELECT ST_ReducePrecision(polygondf.countyshape, 9)
+FROM polygondf
+```
+The new coordinates will only have 9 decimal places.
+
## ST_Reverse
Introduction: Return the geometry with vertex order reversed
diff --git a/docs/api/sql/Function.md b/docs/api/sql/Function.md
index 21821872..59a65c2f 100644
--- a/docs/api/sql/Function.md
+++ b/docs/api/sql/Function.md
@@ -1302,7 +1302,7 @@ It would also sometimes return multiple geometries for a
single geometry input.
## ST_MinimumBoundingCircle
-Introduction: Returns the smallest circle polygon that contains a geometry.
+Introduction: Returns the smallest circle polygon that contains a geometry.
The optional quadrantSegments parameter determines how many segments to use per
quadrant and the default number of segments has been changed to 48 since
v1.5.0.
Format: `ST_MinimumBoundingCircle(geom: geometry, [Optional]
quadrantSegments:int)`
@@ -1552,18 +1552,18 @@ SELECT
ST_AsText(ST_PointOnSurface(ST_GeomFromText('LINESTRING(0 5 1, 0 0 1, 0 1
```
-## ST_PrecisionReduce
+## ST_ReducePrecision
-Introduction: Reduce the decimals places in the coordinates of the geometry to
the given number of decimal places. The last decimal place will be rounded.
+Introduction: Reduce the decimals places in the coordinates of the geometry to
the given number of decimal places. The last decimal place will be rounded.
This function was called ST_PrecisionReduce in versions prior to v1.5.0.
-Format: `ST_PrecisionReduce (A:geometry, B:int)`
+Format: `ST_ReducePrecision (A:geometry, B:int)`
Since: `v1.0.0`
Spark SQL example:
```sql
-SELECT ST_PrecisionReduce(polygondf.countyshape, 9)
+SELECT ST_ReducePrecision(polygondf.countyshape, 9)
FROM polygondf
```
The new coordinates will only have 9 decimal places.
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 5a383b42..0aef2bab 100644
--- a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
+++ b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
@@ -68,6 +68,7 @@ public class Catalog {
new Functions.ST_FlipCoordinates(),
new Functions.ST_GeoHash(),
new Functions.ST_PointOnSurface(),
+ new Functions.ST_ReducePrecision(),
new Functions.ST_Reverse(),
new Functions.ST_GeometryN(),
new Functions.ST_InteriorRingN(),
@@ -111,6 +112,7 @@ public class Catalog {
new Functions.ST_LineSubstring(),
new Functions.ST_MakePolygon(),
new Functions.ST_MakeValid(),
+ new Functions.ST_MinimumBoundingCircle(),
new Functions.ST_Multi(),
new Functions.ST_StartPoint(),
new Functions.ST_SimplifyPreserveTopology(),
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 36a8d29e..90fd657d 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
@@ -352,6 +352,15 @@ public class Functions {
}
}
+ public static class ST_ReducePrecision 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("Integer") Integer precisionScale) {
+ Geometry geom = (Geometry) o;
+ return org.apache.sedona.common.Functions.reducePrecision(geom,
precisionScale);
+ }
+ }
+
public static class ST_Reverse 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) {
@@ -375,7 +384,7 @@ public class Functions {
return org.apache.sedona.common.Functions.interiorRingN(geom, n);
}
}
-
+
public static class ST_PointN 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, int n) {
@@ -691,6 +700,21 @@ public class Functions {
}
}
+ public static class ST_MinimumBoundingCircle 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("Integer") Integer
quadrantSegments) {
+ Geometry geom = (Geometry) o;
+ return
org.apache.sedona.common.Functions.minimumBoundingCircle(geom,
quadrantSegments);
+ }
+
+ @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) {
+ Geometry geom = (Geometry) o;
+ return
org.apache.sedona.common.Functions.minimumBoundingCircle(geom,
BufferParameters.DEFAULT_QUADRANT_SEGMENTS * 6);
+ }
+ }
+
public static class ST_Multi 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) {
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 5016fa8a..4c5b73c1 100644
--- a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
@@ -25,6 +25,7 @@ import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.io.ParseException;
+import org.locationtech.jts.operation.buffer.BufferParameters;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -358,6 +359,14 @@ public class FunctionTest extends TestBase{
assertEquals("POINT (32.01 -117.99)", result.toString());
}
+ @Test
+ public void testReducePrecision() {
+ Table polygonTable = tableEnv.sqlQuery("SELECT
ST_GeomFromText('POINT(0.12 0.23)') AS geom");
+ Table resultTable =
polygonTable.select(call(Functions.ST_ReducePrecision.class.getSimpleName(),
$("geom"), 1));
+ Geometry point = (Geometry) first(resultTable).getField(0);
+ assertEquals("POINT (0.1 0.2)", point.toString());
+ }
+
@Test
public void testReverse() {
Table polygonTable = createPolygonTable(1);
@@ -775,6 +784,26 @@ public class FunctionTest extends TestBase{
assertEquals("MULTIPOLYGON (((1 5, 3 3, 1 1, 1 5)), ((5 3, 7 5, 7 1, 5
3)))", result.toString());
}
+ @Test
+ public void testMinimumBoundingCircle() {
+ Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING (0
0, 1 0)') AS geom");
+ table =
table.select(call(Functions.ST_MinimumBoundingCircle.class.getSimpleName(),
$("geom")));
+ Geometry result = (Geometry) first(table).getField(0);
+ Integer actual = result.getCoordinates().length;
+ Integer expected = BufferParameters.DEFAULT_QUADRANT_SEGMENTS * 6 * 4
+ 1;
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void testMinimumBoundingCircleWithQuadrantSegments() {
+ Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING (0
0, 1 0)') AS geom");
+ table =
table.select(call(Functions.ST_MinimumBoundingCircle.class.getSimpleName(),
$("geom"), 2));
+ Geometry result = (Geometry) first(table).getField(0);
+ Integer actual = result.getCoordinates().length;
+ Integer expected = 2 * 4 + 1;
+ assertEquals(actual, expected);
+ }
+
@Test
public void testMulti() {
Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('POINT (0 0)')
AS geom");
diff --git a/python/sedona/sql/st_functions.py
b/python/sedona/sql/st_functions.py
index 592cbf74..81f067ab 100644
--- a/python/sedona/sql/st_functions.py
+++ b/python/sedona/sql/st_functions.py
@@ -87,7 +87,7 @@ __all__ = [
"ST_NumInteriorRings",
"ST_PointN",
"ST_PointOnSurface",
- "ST_PrecisionReduce",
+ "ST_ReducePrecision",
"ST_RemovePoint",
"ST_Reverse",
"ST_S2CellIDs",
@@ -966,7 +966,7 @@ def ST_PointOnSurface(geometry: ColumnOrName) -> Column:
@validate_argument_types
-def ST_PrecisionReduce(geometry: ColumnOrName, precision: Union[ColumnOrName,
int]) -> Column:
+def ST_ReducePrecision(geometry: ColumnOrName, precision: Union[ColumnOrName,
int]) -> Column:
"""Reduce the precision of the coordinates in geometry to a specified
number of decimal places.
:param geometry: Geometry to reduce the precision of.
@@ -976,7 +976,7 @@ def ST_PrecisionReduce(geometry: ColumnOrName, precision:
Union[ColumnOrName, in
:return: Geometry with precision reduced to the indicated number of
decimal places as a geometry column, empty geometry if an invalid precision is
passed.
:rtype: Column
"""
- return _call_st_function("ST_PrecisionReduce", (geometry, precision))
+ return _call_st_function("ST_ReducePrecision", (geometry, precision))
@validate_argument_types
diff --git a/python/tests/sql/test_dataframe_api.py
b/python/tests/sql/test_dataframe_api.py
index a0ba91ac..5590a514 100644
--- a/python/tests/sql/test_dataframe_api.py
+++ b/python/tests/sql/test_dataframe_api.py
@@ -33,12 +33,12 @@ from tests.test_base import TestBase
test_configurations = [
# constructors
- (stc.ST_GeomFromGeoHash, ("geohash", 4), "constructor",
"ST_PrecisionReduce(geom, 2)", "POLYGON ((0.7 1.05, 1.05 1.05, 1.05 0.88, 0.7
0.88, 0.7 1.05))"),
+ (stc.ST_GeomFromGeoHash, ("geohash", 4), "constructor",
"ST_ReducePrecision(geom, 2)", "POLYGON ((0.7 1.05, 1.05 1.05, 1.05 0.88, 0.7
0.88, 0.7 1.05))"),
(stc.ST_GeomFromGeoJSON, ("geojson",), "constructor", "", "POINT (0 1)"),
(stc.ST_GeomFromGML, ("gml",), "constructor", "", "LINESTRING (-71.16
42.25, -71.17 42.25, -71.18 42.25)"),
(stc.ST_GeomFromKML, ("kml",), "constructor", "", "LINESTRING (-71.16
42.26, -71.17 42.26)"),
(stc.ST_GeomFromText, ("wkt",), "linestring_wkt", "", "LINESTRING (1 2, 3
4)"),
- (stc.ST_GeomFromWKB, ("wkb",), "constructor", "ST_PrecisionReduce(geom,
2)", "LINESTRING (-2.1 -0.35, -1.5 -0.67)"),
+ (stc.ST_GeomFromWKB, ("wkb",), "constructor", "ST_ReducePrecision(geom,
2)", "LINESTRING (-2.1 -0.35, -1.5 -0.67)"),
(stc.ST_GeomFromWKT, ("wkt",), "linestring_wkt", "", "LINESTRING (1 2, 3
4)"),
(stc.ST_LineFromText, ("wkt",), "linestring_wkt", "", "LINESTRING (1 2, 3
4)"),
(stc.ST_LineStringFromText, ("multiple_point", lambda: f.lit(',')),
"constructor", "", "LINESTRING (0 0, 1 0, 1 1, 0 0)"),
@@ -70,10 +70,10 @@ test_configurations = [
(stf.ST_AsText, ("point",), "point_geom", "", "POINT (0 1)"),
(stf.ST_Azimuth, ("a", "b"), "two_points", "geom * 180.0 / pi()", 90.0),
(stf.ST_Boundary, ("geom",), "triangle_geom", "", "LINESTRING (0 0, 1 0, 1
1, 0 0)"),
- (stf.ST_Buffer, ("point", 1.0), "point_geom", "ST_PrecisionReduce(geom,
2)", "POLYGON ((0.98 0.8, 0.92 0.62, 0.83 0.44, 0.71 0.29, 0.56 0.17, 0.38
0.08, 0.2 0.02, 0 0, -0.2 0.02, -0.38 0.08, -0.56 0.17, -0.71 0.29, -0.83 0.44,
-0.92 0.62, -0.98 0.8, -1 1, -0.98 1.2, -0.92 1.38, -0.83 1.56, -0.71 1.71,
-0.56 1.83, -0.38 1.92, -0.2 1.98, 0 2, 0.2 1.98, 0.38 1.92, 0.56 1.83, 0.71
1.71, 0.83 1.56, 0.92 1.38, 0.98 1.2, 1 1, 0.98 0.8))"),
+ (stf.ST_Buffer, ("point", 1.0), "point_geom", "ST_ReducePrecision(geom,
2)", "POLYGON ((0.98 0.8, 0.92 0.62, 0.83 0.44, 0.71 0.29, 0.56 0.17, 0.38
0.08, 0.2 0.02, 0 0, -0.2 0.02, -0.38 0.08, -0.56 0.17, -0.71 0.29, -0.83 0.44,
-0.92 0.62, -0.98 0.8, -1 1, -0.98 1.2, -0.92 1.38, -0.83 1.56, -0.71 1.71,
-0.56 1.83, -0.38 1.92, -0.2 1.98, 0 2, 0.2 1.98, 0.38 1.92, 0.56 1.83, 0.71
1.71, 0.83 1.56, 0.92 1.38, 0.98 1.2, 1 1, 0.98 0.8))"),
(stf.ST_BuildArea, ("geom",), "multiline_geom", "ST_Normalize(geom)",
"POLYGON ((0 0, 1 1, 1 0, 0 0))"),
(stf.ST_BoundingDiagonal, ("geom",), "square_geom",
"ST_BoundingDiagonal(geom)", "LINESTRING (1 0, 2 1)"),
- (stf.ST_Centroid, ("geom",), "triangle_geom", "ST_PrecisionReduce(geom,
2)", "POINT (0.67 0.33)"),
+ (stf.ST_Centroid, ("geom",), "triangle_geom", "ST_ReducePrecision(geom,
2)", "POINT (0.67 0.33)"),
(stf.ST_Collect, (lambda: f.expr("array(a, b)"),), "two_points", "",
"MULTIPOINT Z (0 0 0, 3 0 4)"),
(stf.ST_Collect, ("a", "b"), "two_points", "", "MULTIPOINT Z (0 0 0, 3 0
4)"),
(stf.ST_ClosestPoint, ("point", "line",), "point_and_line", "", "POINT (0
1)"),
@@ -116,8 +116,8 @@ test_configurations = [
(stf.ST_LineSubstring, ("line", 0.5, 1.0), "linestring_geom", "",
"LINESTRING (2.5 0, 3 0, 4 0, 5 0)"),
(stf.ST_MakeValid, ("geom",), "invalid_geom", "", "MULTIPOLYGON (((1 5, 3
3, 1 1, 1 5)), ((5 3, 7 5, 7 1, 5 3)))"),
(stf.ST_MakePolygon, ("geom",), "closed_linestring_geom", "", "POLYGON ((0
0, 1 0, 1 1, 0 0))"),
- (stf.ST_MinimumBoundingCircle, ("line",), "linestring_geom",
"ST_PrecisionReduce(geom, 2)", "POLYGON ((4.95 -0.49, 4.81 -0.96, 4.58 -1.39,
4.27 -1.77, 3.89 -2.08, 3.46 -2.31, 2.99 -2.45, 2.5 -2.5, 2.01 -2.45, 1.54
-2.31, 1.11 -2.08, 0.73 -1.77, 0.42 -1.39, 0.19 -0.96, 0.05 -0.49, 0 0, 0.05
0.49, 0.19 0.96, 0.42 1.39, 0.73 1.77, 1.11 2.08, 1.54 2.31, 2.01 2.45, 2.5
2.5, 2.99 2.45, 3.46 2.31, 3.89 2.08, 4.27 1.77, 4.58 1.39, 4.81 0.96, 4.95
0.49, 5 0, 4.95 -0.49))"),
- (stf.ST_MinimumBoundingCircle, ("line", 2), "linestring_geom",
"ST_PrecisionReduce(geom, 2)", "POLYGON ((4.27 -1.77, 2.5 -2.5, 0.73 -1.77, 0
0, 0.73 1.77, 2.5 2.5, 4.27 1.77, 5 0, 4.27 -1.77))"),
+ (stf.ST_MinimumBoundingCircle, ("line", 8), "linestring_geom",
"ST_ReducePrecision(geom, 2)", "POLYGON ((4.95 -0.49, 4.81 -0.96, 4.58 -1.39,
4.27 -1.77, 3.89 -2.08, 3.46 -2.31, 2.99 -2.45, 2.5 -2.5, 2.01 -2.45, 1.54
-2.31, 1.11 -2.08, 0.73 -1.77, 0.42 -1.39, 0.19 -0.96, 0.05 -0.49, 0 0, 0.05
0.49, 0.19 0.96, 0.42 1.39, 0.73 1.77, 1.11 2.08, 1.54 2.31, 2.01 2.45, 2.5
2.5, 2.99 2.45, 3.46 2.31, 3.89 2.08, 4.27 1.77, 4.58 1.39, 4.81 0.96, 4.95
0.49, 5 0, 4.95 -0.49))"),
+ (stf.ST_MinimumBoundingCircle, ("line", 2), "linestring_geom",
"ST_ReducePrecision(geom, 2)", "POLYGON ((4.27 -1.77, 2.5 -2.5, 0.73 -1.77, 0
0, 0.73 1.77, 2.5 2.5, 4.27 1.77, 5 0, 4.27 -1.77))"),
(stf.ST_MinimumBoundingRadius, ("line",), "linestring_geom", "",
{"center": "POINT (2.5 0)", "radius": 2.5}),
(stf.ST_Multi, ("point",), "point_geom", "", "MULTIPOINT (0 1)"),
(stf.ST_Normalize, ("geom",), "triangle_geom", "", "POLYGON ((0 0, 1 1, 1
0, 0 0))"),
@@ -128,7 +128,7 @@ test_configurations = [
(stf.ST_NumPoints, ("line",), "linestring_geom", "", 6),
(stf.ST_PointN, ("line", 2), "linestring_geom", "", "POINT (1 0)"),
(stf.ST_PointOnSurface, ("line",), "linestring_geom", "", "POINT (2 0)"),
- (stf.ST_PrecisionReduce, ("geom", 1), "precision_reduce_point", "", "POINT
(0.1 0.2)"),
+ (stf.ST_ReducePrecision, ("geom", 1), "precision_reduce_point", "", "POINT
(0.1 0.2)"),
(stf.ST_RemovePoint, ("line", 1), "linestring_geom", "", "LINESTRING (0 0,
2 0, 3 0, 4 0, 5 0)"),
(stf.ST_Reverse, ("line",), "linestring_geom", "", "LINESTRING (5 0, 4 0,
3 0, 2 0, 1 0, 0 0)"),
(stf.ST_S2CellIDs, ("point", 30), "point_geom", "", [1153451514845492609]),
@@ -141,7 +141,7 @@ test_configurations = [
(stf.ST_SubDivide, ("line", 5), "linestring_geom", "", ["LINESTRING (0 0,
2.5 0)", "LINESTRING (2.5 0, 5 0)"]),
(stf.ST_SubDivideExplode, ("line", 5), "linestring_geom",
"collect_list(geom)", ["LINESTRING (0 0, 2.5 0)", "LINESTRING (2.5 0, 5 0)"]),
(stf.ST_SymDifference, ("a", "b"), "overlapping_polys", "", "MULTIPOLYGON
(((1 0, 0 0, 0 1, 1 1, 1 0)), ((2 0, 2 1, 3 1, 3 0, 2 0)))"),
- (stf.ST_Transform, ("point", lambda: f.lit("EPSG:4326"), lambda:
f.lit("EPSG:32649")), "point_geom", "ST_PrecisionReduce(geom, 2)", "POINT
(-33788209.77 0)"),
+ (stf.ST_Transform, ("point", lambda: f.lit("EPSG:4326"), lambda:
f.lit("EPSG:32649")), "point_geom", "ST_ReducePrecision(geom, 2)", "POINT
(-33788209.77 0)"),
(stf.ST_Translate, ("geom", 1.0, 1.0,), "square_geom", "", "POLYGON ((2 1,
2 2, 3 2, 3 1, 2 1))"),
(stf.ST_Union, ("a", "b"), "overlapping_polys", "", "POLYGON ((1 0, 0 0, 0
1, 1 1, 2 1, 3 1, 3 0, 2 0, 1 0))"),
(stf.ST_X, ("b",), "two_points", "", 3.0),
@@ -270,9 +270,9 @@ wrong_type_configurations = [
(stf.ST_PointN, ("", None)),
(stf.ST_PointN, ("", 2.0)),
(stf.ST_PointOnSurface, (None,)),
- (stf.ST_PrecisionReduce, (None, 1)),
- (stf.ST_PrecisionReduce, ("", None)),
- (stf.ST_PrecisionReduce, ("", 1.0)),
+ (stf.ST_ReducePrecision, (None, 1)),
+ (stf.ST_ReducePrecision, ("", None)),
+ (stf.ST_ReducePrecision, ("", 1.0)),
(stf.ST_RemovePoint, (None, 1)),
(stf.ST_RemovePoint, ("", None)),
(stf.ST_RemovePoint, ("", 1.0)),
diff --git a/python/tests/sql/test_function.py
b/python/tests/sql/test_function.py
index a02a7ab0..2954d5a2 100644
--- a/python/tests/sql/test_function.py
+++ b/python/tests/sql/test_function.py
@@ -230,11 +230,11 @@ class TestPredicateJoin(TestBase):
def test_st_precision_reduce(self):
test_table = self.spark.sql(
- """SELECT
ST_PrecisionReduce(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 8)""")
+ """SELECT
ST_ReducePrecision(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 8)""")
test_table.show(truncate=False)
assert test_table.take(1)[0][0].x == 0.12345679
test_table = self.spark.sql(
- """SELECT
ST_PrecisionReduce(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 11)""")
+ """SELECT
ST_ReducePrecision(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 11)""")
test_table.show(truncate=False)
assert test_table.take(1)[0][0].x == 0.12345678901
diff --git a/python/tests/streaming/spark/test_constructor_functions.py
b/python/tests/streaming/spark/test_constructor_functions.py
index 3ab4258d..26668ba8 100644
--- a/python/tests/streaming/spark/test_constructor_functions.py
+++ b/python/tests/streaming/spark/test_constructor_functions.py
@@ -100,7 +100,7 @@ SEDONA_LISTED_SQL_FUNCTIONS = [
.with_expected_result(1.0)
.with_transform("ST_AREA")),
(SuiteContainer.empty()
- .with_function_name("ST_PrecisionReduce")
+ .with_function_name("ST_ReducePrecision")
.with_arguments(["ST_GeomFromText('POLYGON ((21 53, 22 53, 22 52, 21 52,
21 53))')", "9"])
.with_expected_result(1.0)
.with_transform("ST_AREA")),
@@ -267,13 +267,8 @@ SEDONA_LISTED_SQL_FUNCTIONS = [
(SuiteContainer.empty()
.with_function_name("ST_MinimumBoundingCircle")
.with_arguments([
- "ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))')"
- ])
- .with_expected_result(3.121445152258052)
- .with_transform("ST_AREA")),
- (SuiteContainer.empty()
- .with_function_name("ST_MinimumBoundingCircle")
- .with_arguments(["ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))')"])
+ "ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))')",
+ "8"])
.with_expected_result(3.121445152258052)
.with_transform("ST_AREA")),
(SuiteContainer.empty()
diff --git a/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
b/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
index a66d4cae..dcbf198c 100644
--- a/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
+++ b/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
@@ -75,7 +75,7 @@ object Catalog {
function[ST_Union](),
function[ST_IsValid](),
function[ST_IsEmpty](),
- function[ST_PrecisionReduce](),
+ function[ST_ReducePrecision](),
function[ST_Equals](),
function[ST_Touches](),
function[ST_Overlaps](),
@@ -102,7 +102,7 @@ object Catalog {
function[ST_ClosestPoint](),
function[ST_Boundary](),
function[ST_MinimumBoundingRadius](),
-
function[ST_MinimumBoundingCircle](BufferParameters.DEFAULT_QUADRANT_SEGMENTS),
+
function[ST_MinimumBoundingCircle](BufferParameters.DEFAULT_QUADRANT_SEGMENTS *
6),
function[ST_EndPoint](),
function[ST_ExteriorRing](),
function[ST_GeometryN](),
diff --git
a/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
b/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
index 676e1594..235b38bd 100644
---
a/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
+++
b/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
@@ -303,7 +303,7 @@ case class ST_SimplifyPreserveTopology(inputExpressions:
Seq[Expression])
* @param inputExpressions The first arg is a geom and the second arg is an
integer scale, specifying the number of decimal places of the new coordinate.
The last decimal place will
* be rounded to the nearest number.
*/
-case class ST_PrecisionReduce(inputExpressions: Seq[Expression])
+case class ST_ReducePrecision(inputExpressions: Seq[Expression])
extends InferredExpression(Functions.reducePrecision _) {
protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) =
{
diff --git
a/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
b/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
index 4bfec2ec..05045ba9 100644
---
a/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
+++
b/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala
@@ -178,8 +178,8 @@ object st_functions extends DataFrameAPI {
def ST_MakeValid(geometry: Column, keepCollapsed: Column): Column =
wrapExpression[ST_MakeValid](geometry, keepCollapsed)
def ST_MakeValid(geometry: String, keepCollapsed: Boolean): Column =
wrapExpression[ST_MakeValid](geometry, keepCollapsed)
- def ST_MinimumBoundingCircle(geometry: Column): Column =
wrapExpression[ST_MinimumBoundingCircle](geometry,
BufferParameters.DEFAULT_QUADRANT_SEGMENTS)
- def ST_MinimumBoundingCircle(geometry: String): Column =
wrapExpression[ST_MinimumBoundingCircle](geometry,
BufferParameters.DEFAULT_QUADRANT_SEGMENTS)
+ def ST_MinimumBoundingCircle(geometry: Column): Column =
wrapExpression[ST_MinimumBoundingCircle](geometry,
BufferParameters.DEFAULT_QUADRANT_SEGMENTS * 6)
+ def ST_MinimumBoundingCircle(geometry: String): Column =
wrapExpression[ST_MinimumBoundingCircle](geometry,
BufferParameters.DEFAULT_QUADRANT_SEGMENTS * 6)
def ST_MinimumBoundingCircle(geometry: Column, quadrantSegments: Column):
Column = wrapExpression[ST_MinimumBoundingCircle](geometry, quadrantSegments)
def ST_MinimumBoundingCircle(geometry: String, quadrantSegments: Int):
Column = wrapExpression[ST_MinimumBoundingCircle](geometry, quadrantSegments)
@@ -210,8 +210,8 @@ object st_functions extends DataFrameAPI {
def ST_PointOnSurface(geometry: Column): Column =
wrapExpression[ST_PointOnSurface](geometry)
def ST_PointOnSurface(geometry: String): Column =
wrapExpression[ST_PointOnSurface](geometry)
- def ST_PrecisionReduce(geometry: Column, precision: Column): Column =
wrapExpression[ST_PrecisionReduce](geometry, precision)
- def ST_PrecisionReduce(geometry: String, precision: Int): Column =
wrapExpression[ST_PrecisionReduce](geometry, precision)
+ def ST_ReducePrecision(geometry: Column, precision: Column): Column =
wrapExpression[ST_ReducePrecision](geometry, precision)
+ def ST_ReducePrecision(geometry: String, precision: Int): Column =
wrapExpression[ST_ReducePrecision](geometry, precision)
def ST_RemovePoint(lineString: Column, index: Column): Column =
wrapExpression[ST_RemovePoint](lineString, index)
def ST_RemovePoint(lineString: String, index: Int): Column =
wrapExpression[ST_RemovePoint](lineString, index)
diff --git
a/sql/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
b/sql/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
index 9a76e76f..b02bf51d 100644
---
a/sql/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
+++
b/sql/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
@@ -22,6 +22,7 @@ import scala.collection.mutable.WrappedArray
import org.apache.commons.codec.binary.Hex
import org.apache.spark.sql.functions.{col, lit}
import org.locationtech.jts.geom.Geometry
+import org.locationtech.jts.operation.buffer.BufferParameters
import org.apache.spark.sql.sedona_sql.expressions.st_constructors._
import org.apache.spark.sql.sedona_sql.expressions.st_functions._
import org.apache.spark.sql.sedona_sql.expressions.st_predicates._
@@ -177,7 +178,7 @@ class dataFrameAPITestScala extends TestBaseScala {
it("Passed ST_Buffer") {
val polygonDf = sparkSession.sql("SELECT ST_Point(1.0, 1.0) AS geom")
- val df = polygonDf.select(ST_Buffer("geom",
1.0).as("geom")).selectExpr("ST_PrecisionReduce(geom, 2)")
+ val df = polygonDf.select(ST_Buffer("geom",
1.0).as("geom")).selectExpr("ST_ReducePrecision(geom, 2)")
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText()
val expectedResult = "POLYGON ((1.98 0.8, 1.92 0.62, 1.83 0.44, 1.71
0.29, 1.56 0.17, 1.38 0.08, 1.2 0.02, 1 0, 0.8 0.02, 0.62 0.08, 0.44 0.17, 0.29
0.29, 0.17 0.44, 0.08 0.62, 0.02 0.8, 0 1, 0.02 1.2, 0.08 1.38, 0.17 1.56, 0.29
1.71, 0.44 1.83, 0.62 1.92, 0.8 1.98, 1 2, 1.2 1.98, 1.38 1.92, 1.56 1.83, 1.71
1.71, 1.83 1.56, 1.92 1.38, 1.98 1.2, 2 1, 1.98 0.8))"
assert(actualResult == expectedResult)
@@ -257,7 +258,7 @@ class dataFrameAPITestScala extends TestBaseScala {
it("Passed ST_Transform") {
val pointDf = sparkSession.sql("SELECT ST_Point(1.0, 1.0) AS geom")
- val df = pointDf.select(ST_Transform($"geom", lit("EPSG:4326"),
lit("EPSG:32649")).as("geom")).selectExpr("ST_PrecisionReduce(geom, 2)")
+ val df = pointDf.select(ST_Transform($"geom", lit("EPSG:4326"),
lit("EPSG:32649")).as("geom")).selectExpr("ST_ReducePrecision(geom, 2)")
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText()
val expectedResult = "POINT (-33741810.95 1823994.03)"
assert(actualResult == expectedResult)
@@ -278,9 +279,9 @@ class dataFrameAPITestScala extends TestBaseScala {
assert(actualResult)
}
- it("Passed ST_PrecisionReduce") {
+ it("Passed ST_ReducePrecision") {
val pointDf = sparkSession.sql("SELECT ST_Point(0.12, 0.23) AS geom")
- val df = pointDf.select(ST_PrecisionReduce("geom", 1))
+ val df = pointDf.select(ST_ReducePrecision("geom", 1))
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText()
val expectedResult = "POINT (0.1 0.2)"
assert(actualResult == expectedResult)
@@ -625,15 +626,15 @@ class dataFrameAPITestScala extends TestBaseScala {
it("Passed ST_MinimumBoundingCircle with default quadrantSegments") {
val baseDf = sparkSession.sql("SELECT ST_GeomFromWKT('LINESTRING (0 0, 1
0)') AS geom")
- val df =
baseDf.select(ST_MinimumBoundingCircle("geom").as("geom")).selectExpr("ST_PrecisionReduce(geom,
2)")
- val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText()
- val expectedResult = "POLYGON ((0.99 -0.1, 0.96 -0.19, 0.92 -0.28, 0.85
-0.35, 0.78 -0.42, 0.69 -0.46, 0.6 -0.49, 0.5 -0.5, 0.4 -0.49, 0.31 -0.46, 0.22
-0.42, 0.15 -0.35, 0.08 -0.28, 0.04 -0.19, 0.01 -0.1, 0 0, 0.01 0.1, 0.04 0.19,
0.08 0.28, 0.15 0.35, 0.22 0.42, 0.31 0.46, 0.4 0.49, 0.5 0.5, 0.6 0.49, 0.69
0.46, 0.78 0.42, 0.85 0.35, 0.92 0.28, 0.96 0.19, 0.99 0.1, 1 0, 0.99 -0.1))"
+ val df =
baseDf.select(ST_MinimumBoundingCircle("geom").as("geom")).selectExpr("ST_ReducePrecision(geom,
2)")
+ val actualResult =
df.take(1)(0).get(0).asInstanceOf[Geometry].getCoordinates().length
+ val expectedResult = BufferParameters.DEFAULT_QUADRANT_SEGMENTS * 6 * 4
+ 1;
assert(actualResult == expectedResult)
}
it("Passed ST_MinimumBoundingCircle with specified quadrantSegments") {
val baseDf = sparkSession.sql("SELECT ST_GeomFromWKT('LINESTRING (0 0, 1
0)') AS geom")
- val df = baseDf.select(ST_MinimumBoundingCircle("geom",
2).as("geom")).selectExpr("ST_PrecisionReduce(geom, 2)")
+ val df = baseDf.select(ST_MinimumBoundingCircle("geom",
2).as("geom")).selectExpr("ST_ReducePrecision(geom, 2)")
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText()
val expectedResult = "POLYGON ((0.85 -0.35, 0.5 -0.5, 0.15 -0.35, 0 0,
0.15 0.35, 0.5 0.5, 0.85 0.35, 1 0, 0.85 -0.35))"
assert(actualResult == expectedResult)
diff --git
a/sql/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
b/sql/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
index c8fef629..d1a4d851 100644
--- a/sql/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
+++ b/sql/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
@@ -305,15 +305,15 @@ class functionTestScala extends TestBaseScala with
Matchers with GeometrySample
assert(testtable.take(1).head.get(0) == null)
}
- it("Passed ST_PrecisionReduce") {
+ it("Passed ST_ReducePrecision") {
var testtable = sparkSession.sql(
"""
- |SELECT
ST_PrecisionReduce(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 8)
+ |SELECT
ST_ReducePrecision(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 8)
""".stripMargin)
assert(testtable.take(1)(0).get(0).asInstanceOf[Geometry].getCoordinates()(0).x
== 0.12345679)
testtable = sparkSession.sql(
"""
- |SELECT
ST_PrecisionReduce(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 11)
+ |SELECT
ST_ReducePrecision(ST_GeomFromWKT('Point(0.1234567890123456789
0.1234567890123456789)'), 11)
""".stripMargin)
assert(testtable.take(1)(0).get(0).asInstanceOf[Geometry].getCoordinates()(0).x
== 0.12345678901)
@@ -1388,7 +1388,7 @@ class functionTestScala extends TestBaseScala with
Matchers with GeometrySample
When("Using ST_MinimumBoundingCircle function")
- val circleTable = geometryTable.selectExpr("ST_MinimumBoundingCircle(geom)
as geom")
+ val circleTable = geometryTable.selectExpr("ST_MinimumBoundingCircle(geom,
8) as geom")
val circleTableWithSeg =
geometryTable.selectExpr("ST_MinimumBoundingCircle(geom, 1) as geom")
Then("Result should match List of circles")
@@ -1706,7 +1706,7 @@ class functionTestScala extends TestBaseScala with
Matchers with GeometrySample
assert(functionDf.first().get(0) == null)
functionDf = sparkSession.sql("select ST_SimplifyPreserveTopology(null,
1)")
assert(functionDf.first().get(0) == null)
- functionDf = sparkSession.sql("select ST_PrecisionReduce(null, 1)")
+ functionDf = sparkSession.sql("select ST_ReducePrecision(null, 1)")
assert(functionDf.first().get(0) == null)
functionDf = sparkSession.sql("select ST_AsText(null)")
assert(functionDf.first().get(0) == null)