jiayuasu commented on code in PR #2056:
URL: https://github.com/apache/sedona/pull/2056#discussion_r2190742981
##########
python/sedona/geopandas/geoseries.py:
##########
@@ -1837,10 +1836,208 @@ def to_crs(
"",
)
- def estimate_utm_crs(self, datum_name: str = "WGS 84"):
- raise NotImplementedError(
- "GeoSeries.estimate_utm_crs() is not implemented yet."
+ @property
+ def bounds(self) -> pspd.DataFrame:
+ """Returns a ``DataFrame`` with columns ``minx``, ``miny``, ``maxx``,
+ ``maxy`` values containing the bounds for each geometry.
+
+ See ``GeoSeries.total_bounds`` for the limits of the entire series.
+
+ Examples
+ --------
+ >>> from shapely.geometry import Point, Polygon, LineString
+ >>> d = {'geometry': [Point(2, 1), Polygon([(0, 0), (1, 1), (1, 0)]),
+ ... LineString([(0, 1), (1, 2)])]}
+ >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326")
+ >>> gdf.bounds
+ minx miny maxx maxy
+ 0 2.0 1.0 2.0 1.0
+ 1 0.0 0.0 1.0 1.0
+ 2 0.0 1.0 1.0 2.0
+
+ You can assign the bounds to the ``GeoDataFrame`` as:
+
+ >>> import pandas as pd
+ >>> gdf = pd.concat([gdf, gdf.bounds], axis=1)
+ >>> gdf
+ geometry minx miny maxx maxy
+ 0 POINT (2 1) 2.0 1.0 2.0 1.0
+ 1 POLYGON ((0 0, 1 1, 1 0, 0 0)) 0.0 0.0 1.0 1.0
+ 2 LINESTRING (0 1, 1 2) 0.0 1.0 1.0 2.0
+ """
+ import numpy as np
+
+ col = self.get_first_geometry_column()
+ envelope_series = self._query_geometry_column(
+ f"ST_Envelope(`{col}`)", col, "bounds"
+ )
+
+ bounds = {
+ "minx": [],
+ "miny": [],
+ "maxx": [],
+ "maxy": [],
+ }
+
+ # TODO: look into making this computation more efficient
+ for i in range(len(envelope_series)):
Review Comment:
Maybe using Sedona native functions ST_XMin, XMax, ...?
We want to avoid manipulating data directly in Python.
Maybe this is also a good opportunity to fix this?
https://github.com/apache/sedona/issues/1874
--
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]