geopandas.GeoSeries.clip_by_rect#

GeoSeries.clip_by_rect(xmin, ymin, xmax, ymax)#

返回一个 GeoSeries 给定矩形内的几何图形部分的。

请注意,结果并不完全等于 intersection() 。例如在边缘情况下, clip_by_rect() 不会返回仅与矩形接触的点。请查看下面的示例部分,了解其中一些例外情况。

几何体以一种快速但可能肮脏的方式进行剪裁。不能保证输出是有效的。对于拓扑错误不会引发任何异常。

注意:空几何图形或与指定边界不重叠的几何图形将导致 GEOMETRYCOLLECTION EMPTY

参数
Xmin:浮点数

矩形的最小x值

符号:浮点

矩形的最小y值

Xmax:浮点

矩形的最大x值

Ymax:浮点数

矩形的最大y值

退货
GeoSeries

示例

>>> from shapely.geometry import Polygon, LineString, Point
>>> s = geopandas.GeoSeries(
...     [
...         Polygon([(0, 0), (2, 2), (0, 2)]),
...         Polygon([(0, 0), (2, 2), (0, 2)]),
...         LineString([(0, 0), (2, 2)]),
...         LineString([(2, 0), (0, 2)]),
...         Point(0, 1),
...     ],
...     crs=3857,
... )
>>> bounds = (0, 0, 1, 1)
>>> s
0    POLYGON ((0.000 0.000, 2.000 2.000, 0.000 2.00...
1    POLYGON ((0.000 0.000, 2.000 2.000, 0.000 2.00...
2                LINESTRING (0.000 0.000, 2.000 2.000)
3                LINESTRING (2.000 0.000, 0.000 2.000)
4                                  POINT (0.000 1.000)
dtype: geometry
>>> s.clip_by_rect(*bounds)
0    POLYGON ((0.000 0.000, 0.000 1.000, 1.000 1.00...
1    POLYGON ((0.000 0.000, 0.000 1.000, 1.000 1.00...
2                LINESTRING (0.000 0.000, 1.000 1.000)
3                             GEOMETRYCOLLECTION EMPTY
4                             GEOMETRYCOLLECTION EMPTY
dtype: geometry