Make an invalid geometry valid
st_make_valid(x)
object of class sfg
, sfg
or sf
Object of the same class as x
st_make_valid
uses the lwgeom_makevalid
method also used by the PostGIS command ST_makevalid
. It is only available if the package was linked against liblwgeom, which is currently not the case for the binary CRAN distributions; see the package source code repository for instructions how to install liblwgeom. The example below shows how to run-time check the availability of liblwgeom.
# NOT RUN {
x = st_sfc(st_polygon(list(rbind(c(0,0),c(0.5,0),c(0.5,0.5),c(0.5,0),c(1,0),c(1,1),c(0,1),c(0,0)))))
if (!is.na(sf_extSoftVersion()["lwgeom"])) {
suppressWarnings(st_is_valid(x))
y = st_make_valid(x)
st_is_valid(y)
y %>% st_cast()
}
# }
Run the code above in your browser using DataLab