from shapely.geometry import Polygon, MultiPolygon
from py_tools_ds.geo.vector.topology import fill_holes_within_poly
polygon_1 = Polygon([(0, 0), (5, 0), (5, 5), (0, 5)]) # large poly
polygon_2 = Polygon([(1, 1), (1, 2), (2, 2), (2, 1)]) # small poly within large poly
multipolygon = MultiPolygon([polygon_1, polygon_2])
fill_holes_within_poly(multipolygon)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-8ecef912bc33> in <module>
6 multipolygon = MultiPolygon([polygon_1, polygon_2])
7
----> 8 fill_holes_within_poly(multipolygon)
~/miniconda3/envs/arosics/lib/python3.8/site-packages/py_tools_ds/geo/vector/topology.py in fill_holes_within_poly(poly)
187 lambda GDF_row: Polygon(np.swapaxes(np.array(GDF_row.geometry.exterior.coords.xy), 0, 1)).area, axis=1)
188
--> 189 largest_poly_filled = gdf.loc[gdf['area_filled'].idxmax()]['geometry']
190
191 # return the outer boundary of the largest polygon
~/miniconda3/envs/arosics/lib/python3.8/site-packages/pandas/core/series.py in idxmax(self, axis, skipna, *args, **kwargs)
2166 """
2167 skipna = nv.validate_argmax_with_skipna(skipna, args, kwargs)
-> 2168 i = nanops.nanargmax(self._values, skipna=skipna)
2169 if i == -1:
2170 return np.nan
~/miniconda3/envs/arosics/lib/python3.8/site-packages/pandas/core/nanops.py in _f(*args, **kwargs)
64 if any(self.check(obj) for obj in obj_iter):
65 f_name = f.__name__.replace("nan", "")
---> 66 raise TypeError(
67 f"reduction operation '{f_name}' not allowed for this dtype"
68 )
TypeError: reduction operation 'argmax' not allowed for this dtype