I think the solution here is, whenever a 'NA' / empty ID is found, it sends it down to the next level geometry. So multipolygon goes to polygon, polygon goes to linestring etc.
df <- data.frame(
poly_id = c(1,1,1,1,NA,NA,NA,2,2,2)
, line_id = rep(1,10)
, x = 1:10
, y = 1:10
)
And you'd call to_sf() on this, rather than the specific sf_polygon() calls.
I think the solution here is, whenever a 'NA' / empty ID is found, it sends it down to the next level geometry. So multipolygon goes to polygon, polygon goes to linestring etc.
And you'd call
to_sf()on this, rather than the specificsf_polygon()calls.