as_spatraster()
turns an existing data frame or tibble, into a SpatRaster.
This is a wrapper of terra::rast()
S4 method for data.frame
.
as_spatraster(x, ..., xycols = 1:2, crs = "", digits = 6)
A tibble or data frame.
additional arguments passed on to terra::rast()
.
A vector of integers of length 2 determining the position of the columns that hold the x and y coordinates.
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 pull_crs()
. See Details.
integer to set the precision for detecting whether points are on a regular grid (a low number of digits is a low precision).
A SpatRaster.
If no
crs
is provided and the tibble
has been created with the method as_tibble.SpatRaster()
, the crs
is
inferred from attr(x, "crs")
.
Coercing objects:
as_coordinates()
,
as_tibble()
# NOT RUN {
library(terra)
r <- rast(matrix(1:90, ncol = 3), crs = "epsg:3857")
r
# Create tibble
as_tbl <- as_tibble(r, xy = TRUE)
as_tbl
# From tibble
newrast <- as_spatraster(as_tbl, crs = "epsg:3857")
newrast
# }
Run the code above in your browser using DataLab