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 007bb615 [SEDONA-303] Port all Sedona Spark functions to Sedona Flink 
-- Step 2 (#882)
007bb615 is described below

commit 007bb615397edf26d4e398fac79faadb1b423577
Author: Junhao Liu <[email protected]>
AuthorDate: Tue Jul 4 13:07:00 2023 +0800

    [SEDONA-303] Port all Sedona Spark functions to Sedona Flink -- Step 2 
(#882)
---
 docs/api/flink/Function.md                         | 81 ++++++++++++++++++++++
 .../main/java/org/apache/sedona/flink/Catalog.java |  5 ++
 .../apache/sedona/flink/expressions/Functions.java | 43 ++++++++++++
 .../java/org/apache/sedona/flink/FunctionTest.java | 42 +++++++++++
 4 files changed, 171 insertions(+)

diff --git a/docs/api/flink/Function.md b/docs/api/flink/Function.md
index 5bff4674..a35dc52d 100644
--- a/docs/api/flink/Function.md
+++ b/docs/api/flink/Function.md
@@ -676,6 +676,36 @@ SELECT ST_Dump(ST_GeomFromText('MULTIPOINT ((10 40), (40 
30), (20 20), (30 10))'
 
 Output: `[POINT (10 40), POINT (40 30), POINT (20 20), POINT (30 10)]`
 
+## ST_DumpPoints
+
+Introduction: Returns list of Points which geometry consists of.
+
+Format: `ST_DumpPoints(geom: geometry)`
+
+Since: `v1.5.0`
+
+Example:
+```sql
+SELECT ST_DumpPoints(ST_GeomFromText('LINESTRING (0 0, 1 1, 1 0)'))
+```
+
+Output: `[POINT (0 0), POINT (0 1), POINT (1 1), POINT (1 0), POINT (0 0)]`
+
+## ST_EndPoint
+
+Introduction: Returns last point of given linestring.
+
+Format: `ST_EndPoint(geom: geometry)`
+
+Since: `v1.5.0`
+
+Example:
+```sql
+SELECT ST_EndPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 
170)'))
+```
+
+Output: `POINT(160 170)`
+
 ## ST_Envelope
 
 Introduction: Return the envelop boundary of A
@@ -883,6 +913,20 @@ SELECT ST_GeometryN(ST_GeomFromText('MULTIPOINT((1 2), (3 
4), (5 6), (8 9))'), 1
 
 Output: `POINT (3 4)`
 
+## ST_GeometryType
+
+Introduction: Returns the type of the geometry as a string. EG: 
'ST_Linestring', 'ST_Polygon' etc.
+
+Format: `ST_GeometryType (A:geometry)`
+
+Since: `v1.5.0`
+
+Example:
+```sql
+SELECT ST_GeometryType(polygondf.countyshape)
+FROM polygondf
+```
+
 ## ST_HausdorffDistance
 
 Introduction: Returns a discretized (and hence approximate) [Hausdorff 
distance](https://en.wikipedia.org/wiki/Hausdorff_distance) between the given 2 
geometries. 
@@ -938,6 +982,21 @@ SELECT ST_InteriorRingN(ST_GeomFromText('POLYGON((0 0, 0 
5, 5 5, 5 0, 0 0), (1 1
 
 Output: `LINEARRING (1 1, 2 1, 2 2, 1 2, 1 1)`
 
+## ST_Intersection
+
+Introduction: Return the intersection geometry of A and B
+
+Format: `ST_Intersection (A:geometry, B:geometry)`
+
+Since: `v1.5.0`
+
+Example:
+
+```sql
+SELECT ST_Intersection(polygondf.countyshape, polygondf.countyshape)
+FROM polygondf
+```
+
 ## ST_IsClosed
 
 Introduction: RETURNS true if the LINESTRING start and end point are the same.
@@ -1064,6 +1123,28 @@ Input: `MULTIPOINT((10 40), (40 30), (20 20), (30 10))`
 
 Output: `LINESTRING (10 40, 40 30, 20 20, 30 10)`
 
+## ST_LineInterpolatePoint
+
+Introduction: Returns a point interpolated along a line. First argument must 
be a LINESTRING. Second argument is a Double between 0 and 1 representing 
fraction of total linestring length the point has to be located.
+
+Format: `ST_LineInterpolatePoint (geom: geometry, fraction: Double)`
+
+Since: `v1.5.0`
+
+Example:
+```sql
+SELECT ST_LineInterpolatePoint(ST_GeomFromWKT('LINESTRING(25 50, 100 125, 150 
190)'), 0.2) as Interpolated
+```
+
+Output:
+```
++-----------------------------------------+
+|Interpolated                             |
++-----------------------------------------+
+|POINT (51.5974135047432 76.5974135047432)|
++-----------------------------------------+
+```
+
 ## ST_Normalize
 
 Introduction: Returns the input geometry in its normalized form.
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 1df1fb44..655a0e35 100644
--- a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
+++ b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
@@ -57,8 +57,13 @@ public class Catalog {
                 new Functions.ST_DistanceSpheroid(),
                 new Functions.ST_3DDistance(),
                 new Functions.ST_Dump(),
+                new Functions.ST_DumpPoints(),
+                new Functions.ST_EndPoint(),
+                new Functions.ST_GeometryType(),
+                new Functions.ST_Intersection(),
                 new Functions.ST_Length(),
                 new Functions.ST_LengthSpheroid(),
+                new Functions.ST_LineInterpolatePoint(),
                 new Functions.ST_Transform(),
                 new Functions.ST_FlipCoordinates(),
                 new Functions.ST_GeoHash(),
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 56b1af76..6bde1356 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
@@ -209,7 +209,41 @@ public class Functions {
             return org.apache.sedona.common.Functions.dump(geom1);
         }
     }
+
+    public static class ST_DumpPoints 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 geom1 = (Geometry) o;
+            return org.apache.sedona.common.Functions.dumpPoints(geom1);
+        }
+    }
+
+    public static class ST_EndPoint 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 geom1 = (Geometry) o;
+            return org.apache.sedona.common.Functions.endPoint(geom1);
+        }
+    }
     
+    public static class ST_GeometryType extends ScalarFunction {
+        @DataTypeHint("String")
+        public String eval(@DataTypeHint(value = "RAW", bridgedTo = 
org.locationtech.jts.geom.Geometry.class) Object o) {
+            Geometry geom = (Geometry) o;
+            return org.apache.sedona.common.Functions.geometryType(geom);
+        }
+    }
+
+    public static class ST_Intersection 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 g1,
+        @DataTypeHint(value = "RAW", bridgedTo = 
org.locationtech.jts.geom.Geometry.class) Object g2) {
+            Geometry geom1 = (Geometry) g1;
+            Geometry geom2 = (Geometry) g2;
+            return org.apache.sedona.common.Functions.intersection(geom1, 
geom2);
+        }
+    }
+
     public static class ST_Length extends ScalarFunction {
         @DataTypeHint("Double")
         public Double eval(@DataTypeHint(value = "RAW", bridgedTo = 
org.locationtech.jts.geom.Geometry.class) Object o) {
@@ -226,6 +260,15 @@ public class Functions {
         }
     }
 
+    public static class ST_LineInterpolatePoint 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 fraction) {
+            Geometry geom = (Geometry) o;
+            return 
org.apache.sedona.common.Functions.lineInterpolatePoint(geom, fraction);
+        }
+    }
+
     public static class ST_YMin extends ScalarFunction {
         @DataTypeHint("Double")
         public Double 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 42fd9772..f21298ba 100644
--- a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
@@ -144,6 +144,23 @@ public class FunctionTest extends TestBase{
         assertEquals("POINT (1 1)", result[1].toString());
     }
 
+    @Test
+    public void testDumpPoints() {
+        Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING (0 
0, 1 0)') AS geom");
+        table = 
table.select(call(Functions.ST_DumpPoints.class.getSimpleName(), $("geom")));
+        Geometry[] result = (Geometry[]) first(table).getField(0);
+        assertEquals("POINT (0 0)", result[0].toString());
+        assertEquals("POINT (1 0)", result[1].toString());
+    }
+
+    @Test
+    public void testEndPoint() {
+        Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING(1 
1, 2 2, 3 3)') AS geom");
+        table = table.select(call(Functions.ST_EndPoint.class.getSimpleName(), 
$("geom")));
+        Geometry result = (Geometry) first(table).getField(0);
+        assertEquals("POINT (3 3)", result.toString());
+    }
+
     @Test
     public void testEnvelope() {
         Table linestringTable = createLineStringTable(1);
@@ -159,6 +176,14 @@ public class FunctionTest extends TestBase{
         assertEquals("POINT (-117.99 32.01)", result.toString());
     }
 
+    @Test
+    public void testSTGeometryType() {
+        Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING(1 
1, 2 2, 3 3)') AS geom");
+        table = 
table.select(call(Functions.ST_GeometryType.class.getSimpleName(), $("geom")));
+        String result = (String) first(table).getField(0);
+        assertEquals("ST_LineString", result.toString());
+    }
+
     @Test
     public void testTransform() {
         Table pointTable = createPointTable_real(testDataSize);
@@ -252,6 +277,15 @@ public class FunctionTest extends TestBase{
         assertEquals(Math.sqrt(3), first(pointTable).getField(0));
     }
 
+
+    @Test
+    public void testIntersection() {
+        Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('POINT (0 0)') 
AS g1, ST_GeomFromWKT('LINESTRING ( 0 0, 0 2 )') as g2");
+        table = 
table.select(call(Functions.ST_Intersection.class.getSimpleName(), $("g1"), 
$("g2")));
+        Geometry result = (Geometry) first(table).getField(0);
+        assertEquals("POINT (0 0)", result.toString());
+    }
+
     @Test
     public void testLength() {
         Table polygonTable = createPolygonTable(1);
@@ -270,6 +304,14 @@ public class FunctionTest extends TestBase{
         assertEquals(expected, actual, 0.1);
     }
 
+    @Test
+    public void testLineInterpolatePoint() {
+        Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING (0 
0, 2 0)') AS line");
+        table = 
table.select(call(Functions.ST_LineInterpolatePoint.class.getSimpleName(), 
$("line"), 0.5));
+        Geometry result = (Geometry) first(table).getField(0);
+        assertEquals("POINT (1 0)", result.toString());
+    }
+
     @Test
     public void testYMax() {
         Table polygonTable = createPolygonTable(1);

Reply via email to