check_valid: Check and Repair Geometry Validity

View source: R/check_valid.R

check_validR Documentation

Check and Repair Geometry Validity

Description

Validates sf geometry, repairs invalid features, unifies geometry types, and optionally reprojects. Handles GEOMETRYCOLLECTION artifacts from st_make_valid() by extracting the dominant geometry type.

Usage

check_valid(x, ...)

## S3 method for class 'sf'
check_valid(x, out_prj = sf::st_crs(x), ...)

## S3 method for class 'sfc'
check_valid(x, out_prj = sf::st_crs(x), ...)

Arguments

x

sf data.frame, sfc geometry, or NULL.

...

additional arguments passed to methods.

out_prj

crs. Target CRS for the output, passed to st_transform. Defaults to the CRS of x.

Value

Same class as input: sf data.frame, sfc, or NULL.

Examples

library(sf)
p1 <- st_polygon(list(
  rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 10), c(0, 0)),
  rbind(c(2, 2), c(2, 8), c(8, 8), c(8, 2), c(2, 2))
))
x <- st_sf(geometry = st_sfc(p1, crs = 5070))
result <- check_valid(x)


hydroloom documentation built on Aug. 4, 2026, 1:07 a.m.