geopandas.GeoSeries.count_geometries#

GeoSeries.count_geometries()[来源]#

返回一个 Series,其中包含每个多部分几何体中的几何体数量。

对于单一几何对象,这个值始终为1。对于多部分几何,如 MultiPointMultiLineString,它表示几何中的部分数量。对于 GeometryCollection,它是集合中直接的几何部分的数量(该方法不递归进入集合中的集合)。

另请参阅

GeoSeries.count_coordinates

计算几何图形中的坐标数量

GeoSeries.count_interior_rings

计算内部环的数量

示例

>>> from shapely.geometry import Point, MultiPoint, LineString, MultiLineString
>>> s = geopandas.GeoSeries(
...     [
...         MultiPoint([(0, 0), (1, 1), (1, -1), (0, 1)]),
...         MultiLineString([((0, 0), (1, 1)), ((-1, 0), (1, 0))]),
...         LineString([(0, 0), (1, 1), (1, -1)]),
...         Point(0, 0),
...     ]
... )
>>> s
0     MULTIPOINT ((0 0), (1 1), (1 -1), (0 1))
1    MULTILINESTRING ((0 0, 1 1), (-1 0, 1 0))
2                  LINESTRING (0 0, 1 1, 1 -1)
3                                  POINT (0 0)
dtype: geometry
>>> s.count_geometries()
0    4
1    2
2    1
3    1
dtype: int32