terra has no equivalent of x[, character(0)]: subsetting a SpatVector to zero columns is an error, and x$col <- NULL has to be repeated for every column. This assigns an empty attribute table instead.

drop_values(x)

Arguments

x

A SpatVector, or an object coercible to one via terra::vect().

Value

A SpatVector with the same geometries and no attributes.

Details

Useful when a layer is only wanted for its geometry – as the y of an terra::erase(), for instance, where the attributes are irrelevant and carrying them only bloats the intermediate.

See also

Other SpatVector helpers: dissolve_by(), expanse_planar(), nn_distance()

Examples

v <- terra::vect("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")
v$keep_me <- "no"
names(drop_values(v))
#> character(0)