petern48 commented on code in PR #2784:
URL: https://github.com/apache/sedona/pull/2784#discussion_r3013539634
##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -495,6 +495,27 @@ def test_to_arrow(self):
def test_clip(self):
pass
+ def test_clip_by_rect(self):
+ # Use rect (0.3, 0.3, 1.7, 1.7) so no test-geometry vertex or hole
+ # coordinate (0, 0.1, 0.2, 1, 2, …) lands on a rectangle boundary.
+ # This avoids boundary-handling differences between JTS and GEOS.
Review Comment:
I played with using `(0, 0.1, 0.2, 1)` as args, and it was quite odd
behavior from geopandas to return empty. (I wonder if it could be a bug in
their code tbh). Regardless, I'm comfortable moving forward given that we
documented the behavior differs for boundary cases.
##########
python/sedona/spark/geopandas/base.py:
##########
@@ -3073,6 +3049,73 @@ def dwithin(self, other, distance, align=None):
"""
return _delegate_to_geometry_column("dwithin", self, other, distance,
align)
+ def clip_by_rect(self, xmin, ymin, xmax, ymax):
+ """Returns a ``GeoSeries`` of the portions of geometry within the
+ given rectangle.
+
+ The geometry is clipped to the rectangle defined by the given
+ coordinates. Geometries that do not intersect the rectangle are
+ returned as empty polygons (``POLYGON EMPTY``).
+
+ .. note::
+ This implementation uses ``ST_Intersection`` with a rectangle
+ envelope, which may produce slightly different results from
+ geopandas' ``clip_by_rect`` in edge cases:
+
+ - Non-intersecting geometries are returned as ``POLYGON EMPTY``,
+ whereas geopandas returns ``GEOMETRYCOLLECTION EMPTY``.
+ - Points on the boundary of the rectangle are considered
+ intersecting and are returned unchanged, whereas geopandas
+ returns ``GEOMETRYCOLLECTION EMPTY``.
Review Comment:
```suggestion
- Points on the boundary of the rectangle are considered
intersecting and are returned unchanged, whereas geopandas
returns ``GEOMETRYCOLLECTION EMPTY`` for boundary-only
intersections.
```
Thanks for documenting this. Slight nit, I think we could reword this a
little better to make it super clear that this only applies when the
intersection only includes boundaries (rather than intersecting interior and
boundaries). If that's not correct, let me know. I'm assuming that's what the
behavior is.
##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -495,6 +495,27 @@ def test_to_arrow(self):
def test_clip(self):
pass
+ def test_clip_by_rect(self):
+ # Use rect (0.3, 0.3, 1.7, 1.7) so no test-geometry vertex or hole
+ # coordinate (0, 0.1, 0.2, 1, 2, …) lands on a rectangle boundary.
+ # This avoids boundary-handling differences between JTS and GEOS.
+ for geom in self.geoms:
+ # Sedona converts LinearRing to LineString, so geometry types
+ # will differ from geopandas results.
+ if isinstance(geom[0], LinearRing):
+ continue
+ # ST_Intersection returns different results for
+ # GeometryCollection inputs compared to GEOS clip_by_rect.
+ if isinstance(geom[0], GeometryCollection):
+ continue
Review Comment:
Did you encounter cases where the behavior differed for these geometries? I
played around with different inputs, and never encountered cases where these
cases failed.
(btw, if this part was llm-generated and you don't know, it's okay to admit
that)
##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -495,6 +495,27 @@ def test_to_arrow(self):
def test_clip(self):
pass
+ def test_clip_by_rect(self):
+ # Use rect (0.3, 0.3, 1.7, 1.7) so no test-geometry vertex or hole
+ # coordinate (0, 0.1, 0.2, 1, 2, …) lands on a rectangle boundary.
+ # This avoids boundary-handling differences between JTS and GEOS.
+ for geom in self.geoms:
+ # Sedona converts LinearRing to LineString, so geometry types
+ # will differ from geopandas results.
+ if isinstance(geom[0], LinearRing):
+ continue
+ # ST_Intersection returns different results for
+ # GeometryCollection inputs compared to GEOS clip_by_rect.
+ if isinstance(geom[0], GeometryCollection):
+ continue
Review Comment:
```suggestion
```
I checked the code out locally and found the tests still pass when these are
removed.
--
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]