> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GeoDataFrame.clip_by_rect

> Returns a GeoSeries of the portions of geometry within the given rectangle.

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` for boundary-only intersections.
</Note>

## Signature

```python theme={"system"}
clip_by_rect(xmin, ymin, xmax, ymax)
```

## Parameters

<ParamField path="xmin" type="float" required>
  Minimum x value of the rectangle.
</ParamField>

<ParamField path="ymin" type="float" required>
  Minimum y value of the rectangle.
</ParamField>

<ParamField path="xmax" type="float" required>
  Maximum x value of the rectangle.
</ParamField>

<ParamField path="ymax" type="float" required>
  Maximum y value of the rectangle.
</ParamField>

## Returns

<ResponseField name="return" type="GeoSeries" />

**See also**

* `GeoSeries.intersection`

## Examples

```python theme={"system"}
>>> from sedona.spark.geopandas import GeoSeries
>>> from shapely.geometry import Polygon, LineString, Point
>>> s = GeoSeries(
...     [
...         Polygon([(0, 0), (2, 0), (2, 2), (0, 2)]),
...         LineString([(0, 0), (2, 2)]),
...         Point(0.5, 0.5),
...     ],
... )
```

```python theme={"system"}
>>> s.clip_by_rect(0, 0, 1, 1)
0    POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))
1                   LINESTRING (0 0, 1 1)
2                         POINT (0.5 0.5)
dtype: geometry
```

Geometries that do not intersect the rectangle are returned as
empty:

```python theme={"system"}
>>> GeoSeries([Point(5, 5)]).clip_by_rect(0, 0, 1, 1)
0    POLYGON EMPTY
dtype: geometry
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.