You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2022/09/06 00:53:00 UTC
[incubator-sedona] branch master updated: [SEDONA-161] Add ST_Boundary to the Flink API (#681)
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/incubator-sedona.git
The following commit(s) were added to refs/heads/master by this push:
new e8077154 [SEDONA-161] Add ST_Boundary to the Flink API (#681)
e8077154 is described below
commit e8077154e27dc191dcedb953b5ec978de3bdd8e5
Author: Kengo Seki <se...@apache.org>
AuthorDate: Tue Sep 6 09:52:56 2022 +0900
[SEDONA-161] Add ST_Boundary to the Flink API (#681)
---
.../src/main/java/org/apache/sedona/common/Functions.java | 4 ++++
docs/api/flink/Function.md | 15 +++++++++++++++
flink/src/main/java/org/apache/sedona/flink/Catalog.java | 5 +++--
.../org/apache/sedona/flink/expressions/Functions.java | 8 ++++++++
.../test/java/org/apache/sedona/flink/FunctionTest.java | 8 ++++++++
.../spark/sql/sedona_sql/expressions/Functions.scala | 11 +----------
6 files changed, 39 insertions(+), 12 deletions(-)
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 11498f99..4e5b631b 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -54,6 +54,10 @@ public class Functions {
return azimuth < 0 ? azimuth + (2 * Math.PI) : azimuth;
}
+ public static Geometry boundary(Geometry geometry) {
+ return geometry.getBoundary();
+ }
+
public static Geometry buffer(Geometry geometry, double radius) {
return geometry.buffer(radius);
}
diff --git a/docs/api/flink/Function.md b/docs/api/flink/Function.md
index 760721cc..04583b68 100644
--- a/docs/api/flink/Function.md
+++ b/docs/api/flink/Function.md
@@ -152,6 +152,21 @@ SELECT ST_Azimuth(ST_POINT(0.0, 25.0), ST_POINT(0.0, 0.0))
Output: `3.141592653589793`
+## ST_Boundary
+
+Introduction: Returns the closure of the combinatorial boundary of this Geometry.
+
+Format: `ST_Boundary(geom: geometry)`
+
+Since: `v1.3.0`
+
+Example:
+```SQL
+SELECT ST_Boundary(ST_GeomFromText('POLYGON ((1 1, 0 0, -1 1, 1 1))'))
+```
+
+Output: `LINEARRING (1 1, 0 0, -1 1, 1 1)`
+
## ST_Buffer
Introduction: Returns a geometry/geography that represents all points whose distance from this Geometry/geography is less than or equal to distance.
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 97244865..62807f70 100644
--- a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
+++ b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
@@ -32,10 +32,11 @@ public class Catalog {
new Constructors.ST_GeomFromWKB(),
new Constructors.ST_GeomFromGeoJSON(),
new Constructors.ST_GeomFromGeoHash(),
- new Functions.ST_Area(),
- new Functions.ST_Azimuth(),
new Constructors.ST_GeomFromGML(),
new Constructors.ST_GeomFromKML(),
+ new Functions.ST_Area(),
+ new Functions.ST_Azimuth(),
+ new Functions.ST_Boundary(),
new Functions.ST_Buffer(),
new Functions.ST_Distance(),
new Functions.ST_3DDistance(),
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 e11ba35e..25d8ecdd 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
@@ -38,6 +38,14 @@ public class Functions {
}
}
+ public static class ST_Boundary 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) {
+ Geometry geom = (Geometry) o;
+ return org.apache.sedona.common.Functions.boundary(geom);
+ }
+ }
+
public static class ST_Buffer 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)
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 bd3a8d24..6869c601 100644
--- a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
@@ -52,6 +52,14 @@ public class FunctionTest extends TestBase{
assertEquals(45, ((double) first(pointTable).getField(0)) / (Math.PI * 2) * 360, 0);
}
+ @Test
+ public void testBoundary() {
+ Table polygonTable = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('POLYGON ((1 1, 0 0, -1 1, 1 1))') AS geom");
+ Table boundaryTable = polygonTable.select(call(Functions.ST_Boundary.class.getSimpleName(), $("geom")));
+ Geometry result = (Geometry) first(boundaryTable).getField(0);
+ assertEquals("LINEARRING (1 1, 0 0, -1 1, 1 1)", result.toString());
+ }
+
@Test
public void testBuffer() {
Table pointTable = createPointTable_real(testDataSize);
diff --git a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
index 73b351f7..67d1eac7 100644
--- a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
+++ b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
@@ -584,16 +584,7 @@ case class ST_StartPoint(inputExpressions: Seq[Expression])
case class ST_Boundary(inputExpressions: Seq[Expression])
- extends UnaryGeometryExpression with CodegenFallback {
-
- override protected def nullSafeEval(geometry: Geometry): Any = {
- val geometryBoundary = geometry.getBoundary
- geometryBoundary.toGenericArrayData
- }
-
- override def dataType: DataType = GeometryUDT
-
- override def children: Seq[Expression] = inputExpressions
+ extends InferredUnaryExpression(Functions.boundary) {
protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = {
copy(inputExpressions = newChildren)