View source: R/as_spatvector.R
as_spatvector | R Documentation |
SpatVector
as_spatvector()
turns an existing object into a SpatVector
. This is a
wrapper of terra::vect()
S4 method for signature data.frame
.
as_spatvector(x, ...)
## S3 method for class 'data.frame'
as_spatvector(x, ..., geom = c("lon", "lat"), crs = "")
## S3 method for class 'sf'
as_spatvector(x, ...)
## S3 method for class 'sfc'
as_spatvector(x, ...)
## S3 method for class 'SpatVector'
as_spatvector(x, ...)
x |
A |
... |
additional arguments passed on to |
geom |
character. The field name(s) with the geometry data. Either two names for x and y coordinates of points, or a single name for a single column with WKT geometries. |
crs |
A crs on several formats (PROJ.4, WKT, EPSG code, ..) or
and spatial object from sf or terra that includes the
target coordinate reference system. See |
This function differs from terra::vect()
on the following:
geometries with NA
or ""
values are removed prior to conversion
If x
is a grouped data frame (see dplyr::group_by()
) the grouping
vars are transferred and a "grouped" SpatVector
is created (see
group_by.SpatVector()
).
If no crs
is provided and the tibble has been created with the method
as_tibble.SpatVector()
, the crs
is inferred from
attr(x, "crs")
.
Handles correctly the conversion of EMPTY
geometries between
sf and terra.
A SpatVector
.
terra::vect()
pull_crs()
for retrieving crs, and the corresponding utils sf::st_crs()
and terra::crs()
.
Coercing objects:
as_coordinates()
,
as_sf()
,
as_spatraster()
,
as_tibble.Spat
,
fortify.Spat
library(terra)
v <- vect(matrix(1:80, ncol = 2), crs = "EPSG:3857")
v$cat <- sample(LETTERS[1:4], size = nrow(v), replace = TRUE)
v
# Create tibble
as_tbl <- as_tibble(v, geom = "WKT")
as_tbl
# From tibble
newvect <- as_spatvector(as_tbl, geom = "geometry", crs = "EPSG:3857")
newvect
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.