For several use cases in geopandas (the explode method, for plotting), it would be useful to have a function that explodes multi-geometries.
In pseudo-python (and only for an array with only multi-geometries, would of course this needs to be generalized, but for illustration purposes), this could look like:
def flatten_multipolygons(arr):
indices = []
res = []
for i, geom in enumerate(arr):
for j in range(pygeos.get_num_geometries(geom)):
poly = pygeos.get_geometry(geom, j)
res.append(poly)
indices.append(i)
return np.array(res, dtype=object), np.array(indices)
(the indices are already possible to calculate based on get_num_geometries(arr))
This is something that could be fairly easily implemented in cython, I think. Although we should check what performance benefit it can give. Thoughts?
Questions are what to explode though. MultiPoint/MultiLineString/MultiPolygon would be clear candidates, but GeometryCollection is maybe less clear (what with Multi geoms inside a GeometryCollection ?).
For several use cases in geopandas (the explode method, for plotting), it would be useful to have a function that explodes multi-geometries.
In pseudo-python (and only for an array with only multi-geometries, would of course this needs to be generalized, but for illustration purposes), this could look like:
(the indices are already possible to calculate based on get_num_geometries(arr))
This is something that could be fairly easily implemented in cython, I think. Although we should check what performance benefit it can give. Thoughts?
Questions are what to explode though. MultiPoint/MultiLineString/MultiPolygon would be clear candidates, but GeometryCollection is maybe less clear (what with Multi geoms inside a GeometryCollection ?).