jiayuasu commented on code in PR #2899:
URL: https://github.com/apache/sedona/pull/2899#discussion_r3182532284
##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -868,6 +868,22 @@ public static String asWKT(Geometry geometry) {
return GeomUtils.getWKT(geometry);
}
+ /** PostGIS-format text for a Box2D: {@code BOX(xmin ymin, xmax ymax)}. NULL
on null input. */
+ public static String asWKT(Box2D box) {
+ if (box == null) {
+ return null;
+ }
+ return "BOX("
+ + box.getXMin()
+ + " "
+ + box.getYMin()
+ + ", "
+ + box.getXMax()
+ + " "
+ + box.getYMax()
+ + ")";
Review Comment:
Renamed in 8007abd1 to `Functions.box2dAsText` so the WKT serializer family
stays a strict serializer. The Spark-side expression is still `ST_AsText`
(which is a label, not a strict WKT contract — already mixed Geometry WKT and
Geography text formats).
##########
common/src/main/java/org/apache/sedona/common/Constructors.java:
##########
@@ -289,6 +289,29 @@ public static Geometry makeEnvelope(double minX, double
minY, double maxX, doubl
return makeEnvelope(minX, minY, maxX, maxY, 0);
}
+ /**
+ * Convert a {@link Box2D} to a closed rectangular polygon. NULL on null
input. Mirrors PostGIS
+ * {@code box2d::geometry}.
+ */
+ public static Geometry geomFromBox2D(Box2D box) {
+ if (box == null) {
+ return null;
+ }
+ double xmin = box.getXMin();
+ double ymin = box.getYMin();
+ double xmax = box.getXMax();
+ double ymax = box.getYMax();
+ Coordinate[] coords =
+ new Coordinate[] {
+ new Coordinate(xmin, ymin),
+ new Coordinate(xmin, ymax),
+ new Coordinate(xmax, ymax),
+ new Coordinate(xmax, ymin),
+ new Coordinate(xmin, ymin)
+ };
+ return GEOMETRY_FACTORY.createPolygon(coords);
Review Comment:
Done in 8007abd1. `geomFromBox2D` now delegates to `polygonFromEnvelope` —
one source of truth for the ring assembly.
##########
common/src/main/java/org/apache/sedona/common/Constructors.java:
##########
@@ -289,6 +289,29 @@ public static Geometry makeEnvelope(double minX, double
minY, double maxX, doubl
return makeEnvelope(minX, minY, maxX, maxY, 0);
}
+ /**
+ * Convert a {@link Box2D} to a closed rectangular polygon. NULL on null
input. Mirrors PostGIS
+ * {@code box2d::geometry}.
+ */
+ public static Geometry geomFromBox2D(Box2D box) {
Review Comment:
Added direct `ConstructorsTest.geomFromBox2D` in 8007abd1 covering happy
path, degenerate box (collapsed to a point), and null input.
##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -868,6 +868,22 @@ public static String asWKT(Geometry geometry) {
return GeomUtils.getWKT(geometry);
}
+ /** PostGIS-format text for a Box2D: {@code BOX(xmin ymin, xmax ymax)}. NULL
on null input. */
+ public static String asWKT(Box2D box) {
Review Comment:
Added direct `FunctionsTest.box2dAsText` in 8007abd1 covering typical case,
full-globe extent, and null input.
--
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]