You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sedona.apache.org by GitBox <gi...@apache.org> on 2022/04/23 04:33:01 UTC

[GitHub] [incubator-sedona] jiayuasu commented on a diff in pull request #621: [Sedona-113] Add ST_PointN to Apache Sedona

jiayuasu commented on code in PR #621:
URL: https://github.com/apache/incubator-sedona/pull/621#discussion_r856841378


##########
docs/api/flink/Function.md:
##########
@@ -152,6 +152,34 @@ Input: `POLYGON ((-0.5 -0.5, -0.5 0.5, 0.5 0.5, 0.5 -0.5, -0.5 -0.5))`
 
 Output: `POLYGON ((-0.5 -0.5, 0.5 -0.5, 0.5 0.5, -0.5 0.5, -0.5 -0.5))`
 
+## ST_PointN

Review Comment:
   Please add docs for ST_ExteriorRing too.



##########
core/src/main/java/org/apache/sedona/core/utils/GeomUtils.java:
##########
@@ -81,6 +84,38 @@ public static Geometry getInteriorPoint(Geometry geometry) {
         return geometry.getInteriorPoint();
     }
 
+    /**
+     * Return the nth point from the given geometry (which could be a linestring or a circular linestring)
+     * If the value of n is negative, return a point backwards
+     * E.g. if n = 1, return 1st point, if n = -1, return last point
+     *
+     * @param lineString from which the nth point is to be returned
+     * @param n is the position of the point in the geometry
+     * @return a point
+     */
+    public static Geometry getNthPoint(LineString lineString, int n) {
+        if (lineString == null || n == 0) {
+            return null;
+        }
+
+        int p = lineString.getNumPoints();
+        if (Math.abs(n) > p) {
+            return null;
+        }
+
+        Coordinate[] nthCoordinate = new Coordinate[1];
+        if (n > 0) {
+            nthCoordinate[0] = lineString.getCoordinates()[n - 1];
+        } else {
+            nthCoordinate[0] = lineString.getCoordinates()[p + n];
+        }
+        return new Point(new CoordinateArraySequence(nthCoordinate), lineString.getFactory());
+    }
+
+    public static Geometry getExteriorRing(Geometry geometry) {
+        return geometry.getFactory().createLinearRing(geometry.getCoordinates());

Review Comment:
   Use this function in JTS Polygon. Dont create LinearRing by coordinates as they might NOT be the rings.https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/Polygon.html#getExteriorRing--



##########
sql/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala:
##########
@@ -105,6 +105,7 @@ object Catalog {
     ST_Multi,
     ST_PointOnSurface,
     ST_Reverse,
+    ST_PointN,

Review Comment:
   Register ST_ExteriorRing as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org