jiayuasu commented on code in PR #2710:
URL: https://github.com/apache/sedona/pull/2710#discussion_r2916440427
##########
python/sedona/spark/geopandas/base.py:
##########
@@ -707,15 +820,81 @@ def envelope(self):
"""
return _delegate_to_geometry_column("envelope", self)
- # def minimum_rotated_rectangle(self):
- # raise NotImplementedError("This method is not implemented yet.")
+ def minimum_rotated_rectangle(self):
+ """Return the minimum rotated rectangle (oriented envelope) that
+ encloses each geometry.
- # @property
- # def exterior(self):
- # raise NotImplementedError("This method is not implemented yet.")
+ Unlike ``envelope``, the rectangle may be rotated to better fit the
+ geometry.
- # def extract_unique_points(self):
- # raise NotImplementedError("This method is not implemented yet.")
+ Returns
+ -------
+ GeoSeries
+
+ Examples
+ --------
+ >>> from sedona.spark.geopandas import GeoSeries
+ >>> from shapely.geometry import MultiPoint
+ >>> s = GeoSeries(
+ ... [MultiPoint([(0, 0), (1, 0), (0.5, 1)])]
+ ... )
+ >>> s.minimum_rotated_rectangle()
+ 0 POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
+ dtype: geometry
+
+ See Also
+ --------
+ GeoSeries.envelope : axis-aligned bounding rectangle
+ GeoSeries.convex_hull : convex hull geometry
+ """
+ return _delegate_to_geometry_column("minimum_rotated_rectangle", self)
+
+ @property
+ def exterior(self):
+ """Return the outer boundary of each polygon geometry.
+
+ Returns a ``GeoSeries`` of LinearRings representing the exterior ring
+ of each polygon. For non-polygon geometries, returns ``None``.
+
Review Comment:
Fixed in ce5e1a8. Updated docstring to say "LineStrings" and "LINESTRING",
and added a note documenting the type difference vs geopandas (which returns
LINEARRING).
##########
python/sedona/spark/geopandas/geoseries.py:
##########
@@ -792,30 +792,24 @@ def is_empty(self) -> pspd.Series:
return _to_bool(result)
def count_coordinates(self):
- # Implementation of the abstract method.
- raise NotImplementedError(
- _not_implemented_error(
- "count_coordinates",
- "Counts the number of coordinate tuples in each geometry.",
- )
+ spark_expr = stf.ST_NPoints(self.spark.column)
+ return self._query_geometry_column(
+ spark_expr,
+ returns_geom=False,
)
def count_geometries(self):
- # Implementation of the abstract method.
- raise NotImplementedError(
- _not_implemented_error(
- "count_geometries",
- "Counts the number of geometries in each multi-geometry or
collection.",
- )
+ spark_expr = stf.ST_NumGeometries(self.spark.column)
+ return self._query_geometry_column(
+ spark_expr,
+ returns_geom=False,
)
def count_interior_rings(self):
- # Implementation of the abstract method.
- raise NotImplementedError(
- _not_implemented_error(
- "count_interior_rings",
- "Counts the number of interior rings (holes) in each polygon.",
- )
+ spark_expr = stf.ST_NumInteriorRings(self.spark.column)
Review Comment:
Fixed in ce5e1a8. Used `F.coalesce(ST_NumInteriorRings(...), F.lit(0))`
instead of the suggested `F.when` chain — simpler and achieves the same result
since coalesce replaces NULL with 0.
--
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]