Examples for 'sf::valid'


Check validity or make an invalid geometry valid

Aliases: valid st_is_valid st_is_valid.sfc st_is_valid.sf st_is_valid.sfg st_make_valid st_make_valid.sfg st_make_valid.sfc

Keywords:

### ** Examples

p1 = st_as_sfc("POLYGON((0 0, 0 10, 10 0, 10 10, 0 0))")
st_is_valid(p1)
[1] FALSE
st_is_valid(st_sfc(st_point(0:1), p1[[1]]), reason = TRUE)
[1] "Valid Geometry"         "Self-intersection[5 5]"
library(sf)
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)))))
suppressWarnings(st_is_valid(x))
[1] FALSE
y = st_make_valid(x)
st_is_valid(y)
[1] TRUE
y %>% st_cast()
Geometry set for 1 feature 
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
CRS:           NA
POLYGON ((0 0, 0 1, 1 1, 1 0, 0.5 0, 0 0))

[Package sf version 1.0-19 Index]