sf
sf copied to clipboard
st_cast fails when casting empty GEOMETRYCOLLECTION geometries to MULTIPOLYGON
Describe the bug It seems like st_cast should be able to cast empty geometries of any type to MULTIPOLYGON, but instead I get this:
st_cast(st_sfc(st_geometrycollection(), st_multipolygon()), 'MULTIPOLYGON')
>Error in x[[1]] : subscript out of bounds
What does work is casting an empty polygon to multipolygon:
st_cast(st_sfc(st_polygon(), st_multipolygon()), 'MULTIPOLYGON')
It looks like the problem is that the code is asking for the first element of the geometry collection, but the list is empty.
See issues #1767 and #1094.