jiayuasu commented on code in PR #2904:
URL: https://github.com/apache/sedona/pull/2904#discussion_r3193308629
##########
python/sedona/spark/sql/st_functions.py:
##########
@@ -649,6 +649,20 @@ def ST_EndPoint(line_string: ColumnOrName) -> Column:
return _call_st_function("ST_EndPoint", line_string)
+@validate_argument_types
+def ST_Box2D(geometry: ColumnOrName) -> Column:
+ """Get the planar bounding box (Box2D) of a geometry.
+
+ Returns NULL for null or empty input.
+
+ :param geometry: Geometry column to compute the bounding box of.
+ :type geometry: ColumnOrName
+ :return: Box2D bounding box of the geometry.
+ :rtype: Column
+ """
+ return _call_st_function("ST_Box2D", geometry)
Review Comment:
Correct catch — confirmed by `dataframe_api.py:78-79` which dispatches via
`getattr(jvm, object_name)`. Added the Scala wrapper `st_functions.ST_Box2D`
(Column + String overloads) in c134508d. Closing #2891 here too.
##########
python/sedona/spark/sql/st_constructors.py:
##########
@@ -550,6 +550,42 @@ def ST_MakePoint(
return _call_constructor_function("ST_MakePoint", (args))
+@validate_argument_types
+def ST_MakeBox2D(
+ lower_left: ColumnOrName,
+ upper_right: ColumnOrName,
+) -> Column:
+ """Construct a Box2D from two corner points (lower-left, upper-right).
+
+ Coordinates are taken verbatim — no swapping or ordering validation. NULL
or
+ empty point inputs return NULL. Non-point inputs raise an error.
+
+ :param lower_left: Lower-left corner Point.
+ :type lower_left: ColumnOrName
+ :param upper_right: Upper-right corner Point.
+ :type upper_right: ColumnOrName
+ :return: Box2D column.
+ :rtype: Column
+ """
+ return _call_constructor_function("ST_MakeBox2D", (lower_left,
upper_right))
Review Comment:
Added `st_constructors.ST_MakeBox2D` (Column + String overloads) in c134508d.
##########
python/sedona/spark/sql/st_constructors.py:
##########
@@ -550,6 +550,42 @@ def ST_MakePoint(
return _call_constructor_function("ST_MakePoint", (args))
+@validate_argument_types
+def ST_MakeBox2D(
+ lower_left: ColumnOrName,
+ upper_right: ColumnOrName,
+) -> Column:
+ """Construct a Box2D from two corner points (lower-left, upper-right).
+
+ Coordinates are taken verbatim — no swapping or ordering validation. NULL
or
+ empty point inputs return NULL. Non-point inputs raise an error.
+
+ :param lower_left: Lower-left corner Point.
+ :type lower_left: ColumnOrName
+ :param upper_right: Upper-right corner Point.
+ :type upper_right: ColumnOrName
+ :return: Box2D column.
+ :rtype: Column
+ """
+ return _call_constructor_function("ST_MakeBox2D", (lower_left,
upper_right))
+
+
+@validate_argument_types
+def ST_GeomFromBox2D(box: ColumnOrName) -> Column:
+ """Convert a Box2D to a Geometry.
+
+ Dispatches on dimensionality (matching PostGIS box2d::geometry and
+ Sedona's ST_Envelope): POINT for 0-D boxes, LINESTRING for 1-D boxes,
+ POLYGON otherwise. NULL on null input.
+
+ :param box: Box2D column to convert.
+ :type box: ColumnOrName
+ :return: Geometry column.
+ :rtype: Column
+ """
+ return _call_constructor_function("ST_GeomFromBox2D", box)
Review Comment:
Added `st_constructors.ST_GeomFromBox2D` (Column + String overloads) in
c134508d.
##########
python/sedona/spark/sql/st_aggregates.py:
##########
@@ -41,6 +41,21 @@ def ST_Envelope_Aggr(geometry: ColumnOrName) -> Column:
return _call_aggregate_function("ST_Envelope_Aggr", geometry)
+@validate_argument_types
+def ST_Extent(geometry: ColumnOrName) -> Column:
+ """Aggregate Function: Get the bounding box (Box2D) of a geometry column.
+
+ Returns NULL when the input contains no rows or all rows are null/empty
+ geometries. Mirrors PostGIS ST_Extent.
+
+ :param geometry: Geometry column to aggregate.
+ :type geometry: ColumnOrName
+ :return: Box2D representing the union of bounding boxes of the geometry
column.
+ :rtype: Column
+ """
+ return _call_aggregate_function("ST_Extent", geometry)
Review Comment:
Added `st_aggregates.ST_Extent` (Column + String overloads) in c134508d,
following the udaf-wrapper pattern of the other aggregates in that file.
##########
python/tests/sql/test_function.py:
##########
@@ -185,6 +185,28 @@ def test_st_shiftlongitude(self):
actual = function_df.take(1)[0][0].wkt
assert actual == "LINESTRING (179 10, -179 10)"
+ def test_st_box_2d(self):
+ df = self.spark.sql("""
+ SELECT
+ ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))'))
AS bbox,
+ ST_Box2D(ST_GeomFromText('POINT EMPTY')) AS bbox_empty,
Review Comment:
Added DataFrame API parametric coverage in `test_dataframe_api.py` for
ST_Box2D, ST_MakeBox2D, ST_GeomFromBox2D, and ST_Extent in c134508d. The
existing `test_dataframe_function` harness handles Box2D return values via
`__eq__` on the Python `Box2D` value class.
--
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]