dtoolkit.geoaccessor.geoseries.hole_counts#
- dtoolkit.geoaccessor.geoseries.hole_counts(s: GeoSeries, /) Series[source]#
Return the number of holes in each Polygon geometries.
A sugar syntax for
s.interiors.apply(len).- Returns:
- Series(int64)
Except for Polygon and MultiPolygon, others will get
NaN.
See also
geopandas.GeoSeries.interiorsInner boundary.
geopandas.GeoSeries.convex_hullDrop holes in Polygon and MultiPolygon.
dtoolkit.geoaccessor.geoseries.has_holedtoolkit.geoaccessor.geoseries.hole_countsdtoolkit.geoaccessor.geodataframe.has_holedtoolkit.geoaccessor.geodataframe.hole_counts
Examples
>>> import dtoolkit.geoaccessor >>> import geopandas as gpd >>> from shapely import LineString, Point, Polygon >>> df = gpd.GeoDataFrame( ... geometry=[ ... Polygon( ... [(0, 0), (0, 5), (5, 5), (5, 0)], ... [[(1, 1), (2, 1), (1, 2)], [(1, 4), (2, 4), (2, 3)]], ... ), ... Polygon([(1, 0), (2, 1), (0, 0)]), ... LineString([(0, 0), (0, 5), (5, 5), (5, 0)]), ... Point(0, 0), ... ] ... ) >>> df geometry 0 POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0), (1 1, 2 1,... 1 POLYGON ((1 0, 2 1, 0 0, 1 0)) 2 LINESTRING (0 0, 0 5, 5 5, 5 0) 3 POINT (0 0) >>> df.hole_counts() 0 2.0 1 0.0 2 NaN 3 NaN dtype: float64