I noticed that the sf package does not have a st_exteriorring function as found in postgis, and googling didn't find a standard solution in sf under some other name, so I decided to create a function and wondered if it would be useful to add to sf. The code is:
st_exteriorring = function(geom) {
require(sf)
if (inherits(geom,"sf"))
st_exteriorring(st_geometry(geom))
if (inherits(geom,"sfc")) {
g2 = lapply(geom,st_exteriorring)
g2 = g2 |> st_as_sfc(g2) |> st_set_crs(st_crs(geom))
return(g2)
}
if (inherits(geom,"MULTIPOLYGON")) {
geom = st_cast(st_as_sfc(list(geom)),"POLYGON",warn=FALSE)
g2 = lapply(geom,st_exteriorring)
g2 = g2 |> st_multipolygon()
return(g2)
}
if (inherits(geom,"POLYGON")) {
return(st_polygon(geom[1]))
}
stop("Bad object type. Expected polygon or multipolygon, but got: ",class(geom)[1])
}
Hi,
I noticed that the
sf
package does not have ast_exteriorring
function as found in postgis, and googling didn't find a standard solution insf
under some other name, so I decided to create a function and wondered if it would be useful to add tosf
. The code is:An example usage would be:
Cheers, David