The clip_by_rect()
function in shapely.ops returns the portion of a geometry within a rectangle.
shapely.ops中的clip_by_rect()函数返回一个几何对象在矩形内的部分。
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.
几何对象以一种快速但可能是粗糙的方式被剪掉。输出不保证是有效的。对于拓扑结构的错误,将不会产生异常。
New in version 1.7.
Requires GEOS 3.5.0 or higher
>>> from shapely.ops import clip_by_rect
>>> polygon = Polygon(
... shell=[(0, 0), (0, 30), (30, 30), (30, 0), (0, 0)],
... holes=[[(10, 10), (20, 10), (20, 20), (10, 20), (10, 10)]],
... )
>>> clipped_polygon = clip_by_rect(polygon, 5, 5, 15, 15)
>>> clipped_polygon
<POLYGON ((5 5, 5 15, 10 15, 10 10, 15 10, 15 5, 5 5))>