| as_sf | R Documentation |
SpatVector to a sf objectas_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.
as_sf(x, ...)
x |
A |
... |
additional arguments passed on to |
A sf object object with an additional tbl_df class, for
pretty printing method.
Coercing objects:
as_coordinates(),
as_spatraster(),
as_spatvector(),
as_tibble.Spat,
fortify.Spat
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.