| as_tibble.Spat | R Documentation |
SpatVector or SpatRaster object to data framesas_tibble() methods for SpatRaster and SpatVector objects.
## S3 method for class 'SpatRaster'
as_tibble(x, ..., xy = FALSE, na.rm = FALSE, .name_repair = "unique")
## S3 method for class 'SpatVector'
as_tibble(x, ..., geom = NULL, .name_repair = "unique")
x |
A |
... |
Arguments passed on to |
xy |
logical. If |
na.rm |
logical. If |
.name_repair |
Treatment of problematic column names:
|
geom |
character or NULL. If not NULL, either "WKT" or "HEX", to get the geometry included in Well-Known-Text or hexadecimal notation. If |
A tibble.
terra::as.data.frame()
Implementation of the generic tibble::as_tibble() function.
SpatRaster and SpatVectorThe tibble is returned with an attribute including the crs of the initial
object in WKT format (see pull_crs()).
When coercing SpatRaster objects to data frames, x and y names are
reserved for geographic coordinates of each cell of the SpatRaster It
should be also noted that terra allows layers with duplicated
names.
In the process of coercing a SpatRaster to a tibble, tidyterra
may rename the layers of your SpatRaster for overcoming this issue.
Specifically, layers may be renamed on the following cases:
Layers with duplicated names.
When coercing to a tibble, if xy = TRUE, layers named x or y would be
renamed.
When working with tidyverse methods (i.e. filter.SpatRaster()), the
latter would happen as well.
tidyterra would display a message informing of the changes on the names of the layer.
The same issue happens for SpatVector with names geometry (when
geom = c("WKT", "HEX")) and x, y (when geom = "XY"). These are
reserved names representing the geometry of the SpatVector (see
terra::as.data.frame()). If geom is not NULL then the logic described
for SpatRaster would apply as well for the columns of the SpatVector.
tibble::as_tibble(), terra::as.data.frame()
Coercing objects:
as_coordinates(),
as_sf(),
as_spatraster(),
as_spatvector(),
fortify.Spat
library(terra)
# SpatRaster
f <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
r <- rast(f)
as_tibble(r, na.rm = TRUE)
as_tibble(r, xy = TRUE)
# SpatVector
f <- system.file("extdata/cyl.gpkg", package = "tidyterra")
v <- vect(f)
as_tibble(v)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.