Checks whether a geometry is valid, or makes an invalid geometry valid
st_is_valid(x, ...) # S3 method for sfc st_is_valid(x, ..., NA_on_exception = TRUE, reason = FALSE) # S3 method for sf st_is_valid(x, ...) # S3 method for sfg st_is_valid(x, ...) st_make_valid(x) # S3 method for sfg st_make_valid(x)
x | object of class |
---|---|
... | passed on to sfc method |
NA_on_exception | logical; if TRUE, for polygons that would otherwise raise a GEOS error (exception, e.g. for a POLYGON having more than zero but less than 4 points, or a LINESTRING having one point) return an |
reason | logical; if |
st_is_valid
returns a logical vector indicating for each geometries of x
whether it is valid.
Object of the same class as x
st_make_valid
uses the lwgeom_makevalid
method also used by the PostGIS command ST_makevalid
if the GEOS version linked to is smaller than 3.8.0, and otherwise the version shipped in GEOS.
#> [1] FALSE#> [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] FALSEy = st_make_valid(x) st_is_valid(y)#> [1] TRUE#> Geometry set for 2 features #> geometry type: GEOMETRY #> dimension: XY #> bbox: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA#>#>