@@ -3073,6 +3073,74 @@ def dwithin(self, other, distance, align=None):
30733073 """
30743074 return _delegate_to_geometry_column ("dwithin" , self , other , distance , align )
30753075
3076+ def clip_by_rect (self , xmin , ymin , xmax , ymax ):
3077+ """Returns a ``GeoSeries`` of the portions of geometry within the
3078+ given rectangle.
3079+
3080+ The geometry is clipped to the rectangle defined by the given
3081+ coordinates. Geometries that do not intersect the rectangle are
3082+ returned as empty polygons (``POLYGON EMPTY``).
3083+
3084+ .. note::
3085+ This implementation uses ``ST_Intersection`` with a rectangle
3086+ envelope, which may produce slightly different results from
3087+ geopandas' ``clip_by_rect`` in edge cases:
3088+
3089+ - Non-intersecting geometries are returned as ``POLYGON EMPTY``,
3090+ whereas geopandas returns ``GEOMETRYCOLLECTION EMPTY``.
3091+ - Points on the boundary of the rectangle are considered
3092+ intersecting and are returned unchanged, whereas geopandas
3093+ returns ``GEOMETRYCOLLECTION EMPTY`` for boundary-only
3094+ intersections.
3095+
3096+ Parameters
3097+ ----------
3098+ xmin : float
3099+ Minimum x value of the rectangle.
3100+ ymin : float
3101+ Minimum y value of the rectangle.
3102+ xmax : float
3103+ Maximum x value of the rectangle.
3104+ ymax : float
3105+ Maximum y value of the rectangle.
3106+
3107+ Returns
3108+ -------
3109+ GeoSeries
3110+
3111+ Examples
3112+ --------
3113+ >>> from sedona.spark.geopandas import GeoSeries
3114+ >>> from shapely.geometry import Polygon, LineString, Point
3115+ >>> s = GeoSeries(
3116+ ... [
3117+ ... Polygon([(0, 0), (2, 0), (2, 2), (0, 2)]),
3118+ ... LineString([(0, 0), (2, 2)]),
3119+ ... Point(0.5, 0.5),
3120+ ... ],
3121+ ... )
3122+
3123+ >>> s.clip_by_rect(0, 0, 1, 1)
3124+ 0 POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))
3125+ 1 LINESTRING (0 0, 1 1)
3126+ 2 POINT (0.5 0.5)
3127+ dtype: geometry
3128+
3129+ Geometries that do not intersect the rectangle are returned as
3130+ empty:
3131+
3132+ >>> GeoSeries([Point(5, 5)]).clip_by_rect(0, 0, 1, 1)
3133+ 0 POLYGON EMPTY
3134+ dtype: geometry
3135+
3136+ See also
3137+ --------
3138+ GeoSeries.intersection
3139+ """
3140+ return _delegate_to_geometry_column (
3141+ "clip_by_rect" , self , xmin , ymin , xmax , ymax
3142+ )
3143+
30763144 def difference (self , other , align = None ):
30773145 """Returns a ``GeoSeries`` of the points in each aligned geometry that
30783146 are not in `other`.
0 commit comments