shapely.clip_by_rect

Contents

shapely.clip_by_rect#

clip_by_rect(geometry, xmin, ymin, xmax, ymax, **kwargs)#

Returns the portion of a geometry within a rectangle.

The geometry is clipped in a fast but possibly dirty way. The output is not guaranteed to be valid. No exceptions will be raised for topological errors.

Note: empty geometries or geometries that do not overlap with the specified bounds will result in GEOMETRYCOLLECTION EMPTY.

Parameters:
geometryGeometry or array_like

The geometry to be clipped

xminfloat

Minimum x value of the rectangle

yminfloat

Minimum y value of the rectangle

xmaxfloat

Maximum x value of the rectangle

ymaxfloat

Maximum y value of the rectangle

**kwargs

See NumPy ufunc docs for other keyword arguments.

Examples

>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (10, 10)])
>>> clip_by_rect(line, 0., 0., 1., 1.)
<LINESTRING (0 0, 1 1)>
>>> polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> clip_by_rect(polygon, 0., 0., 1., 1.)
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>