sf icon indicating copy to clipboard operation
sf copied to clipboard

st_cast fails when casting empty GEOMETRYCOLLECTION geometries to MULTIPOLYGON

Open botanize opened this issue 2 years ago • 0 comments

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.

botanize avatar Jun 16 '22 19:06 botanize