as_sf {tidyterra} | R Documentation |
Coerce a SpatVector
to a sf
object
Description
as_sf()
turns a SpatVector
to sf
object. This is a wrapper
of sf::st_as_sf()
with the particularity that the groups created with
group_by.SpatVector()
are preserved.
Usage
as_sf(x, ...)
Arguments
x |
A |
... |
additional arguments passed on to |
Value
A sf
object object with an additional tbl_df
class, for
pretty printing method.
See Also
Coercing objects:
as_coordinates()
,
as_spatraster()
,
as_spatvector()
,
as_tibble.Spat
,
fortify.Spat
Examples
library(terra)
f <- system.file("extdata/cyl.gpkg", package = "tidyterra")
v <- terra::vect(f)
# This is ungrouped
v
is_grouped_spatvector(v)
# Get an ungrouped data
a_sf <- as_sf(v)
dplyr::is_grouped_df(a_sf)
# Grouped
v$gr <- c("C", "A", "A", "B", "A", "B", "B")
v$gr2 <- rep(c("F", "G", "F"), 3)
gr_v <- group_by(v, gr, gr2)
gr_v
is_grouped_spatvector(gr_v)
group_data(gr_v)
# A sf
a_gr_sf <- as_sf(gr_v)
dplyr::is_grouped_df(a_gr_sf)
group_data(a_gr_sf)
[Package tidyterra version 0.6.1 Index]