jiayuasu commented on code in PR #1527:
URL: https://github.com/apache/sedona/pull/1527#discussion_r1686967197


##########
docs/api/sql/Function.md:
##########
@@ -1216,6 +1216,38 @@ Output:
 POLYGON ((0 0, 0 3, 1 3, 1 0, 0 0))
 ```
 
+## ST_Expand
+
+Introduction: Returns a geometry expanded from the bounding box of the input. 
The expansion can be specified in two ways:

Review Comment:
   Please say this only deal with X, Y, Z value.
   
   If `uniformDelta` is used and the geometry has `Z`, all X, Y, Z will be 
expanded. If only `deltaX` and `deltaY` are specified, only X and Y will be 
expanded even if the geometry has `Z`



##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -90,6 +93,57 @@ public static Geometry boundary(Geometry geometry) {
     return boundary;
   }
 
+  public static Geometry expand(Geometry geometry, double uniformDelta) {
+    return expand(geometry, uniformDelta, uniformDelta, uniformDelta);
+  }
+
+  public static Geometry expand(Geometry geometry, double deltaX, double 
deltaY) {
+    return expand(geometry, deltaX, deltaY, 0);
+  }
+
+  public static Geometry expand(Geometry geometry, double deltaX, double 
deltaY, double deltaZ) {
+    if (geometry == null || geometry.isEmpty()) {
+      return geometry;
+    }
+
+    Coordinate[] coordinates = geometry.getCoordinates();
+    double minX = Double.MAX_VALUE;
+    double maxX = -Double.MAX_VALUE;
+    double minY = Double.MAX_VALUE;
+    double maxY = -Double.MAX_VALUE;
+    double minZ = Double.MAX_VALUE;
+    double maxZ = -Double.MAX_VALUE;
+
+    for (int i = 0; i < coordinates.length; i++) {
+      minX = Math.min(minX, coordinates[i].x);
+      maxX = Math.max(maxX, coordinates[i].x);
+      minY = Math.min(minY, coordinates[i].y);
+      maxY = Math.max(maxY, coordinates[i].y);
+      minZ = Math.min(minZ, coordinates[i].z);
+      maxZ = Math.max(maxZ, coordinates[i].z);

Review Comment:
   When a Geometry does not have Z value, JTS will give NaN 
(https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/Coordinate.html#getZ--).
 Does the `Math` comparison still work in this case?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to