DataBackendRaster | R Documentation |
mlr3::DataBackend for terra::SpatRaster raster objects.
There are two different ways the reading of values is performed internally:
"Block mode" reads complete rows of the raster file and subsets the requested cells. This mode is faster than "cell mode" if the complete raster file is iterated over.
"Cell mode" reads individual cells. This is faster than "block mode" if only a few cells are sampled.
"Block mode" is activated if $data(rows)
is used with a increasing integer sequence e.g. 200:300
.
If only a single cell is requested, "cell mode" is used.
mlr3::DataBackend
-> DataBackendRaster
rownames
(integer()
)
Returns vector of all distinct row identifiers, i.e. the contents of the primary key column.
colnames
(character()
)
Returns vector of all column names.
nrow
(integer(1)
)
Number of rows (observations).
ncol
(integer(1)
)
Number of columns (variables).
stack
(SpatRaster
)
Raster stack.
new()
Creates a new instance of this R6 class.
DataBackendRaster$new(data)
data
(terra::SpatRaster)
The input terra::SpatRaster.
data()
Returns a slice of the raster in the specified format.
Currently, the only supported formats is "data.table"
.
The rows must be addressed as vector of cells indices, columns must be referred to via layer names. Queries for rows with no matching row id and queries for columns with no matching column name are silently ignored.
Rows are guaranteed to be returned in the same order as rows
, columns
may be returned in an arbitrary order. Duplicated row ids result in
duplicated rows, duplicated column names lead to an exception.
DataBackendRaster$data(rows, cols, data_format = "data.table")
rows
integer()
Row indices. Row indices start with 1 in the upper left corner in the
raster, increase from left to right and then from top to bottom. The last
cell is in the bottom right corner and the row index equals the number of
cells in the raster.
cols
character()
Column names.
data_format
(character(1)
)
Desired data format. Currently only "data.table"
supported.
head()
Retrieve the first n
rows.
DataBackendRaster$head(n = 6L)
n
(integer(1)
)
Number of rows.
data.table::data.table()
of the first n
rows.
distinct()
Returns a named list of vectors of distinct values for each column
specified. If na_rm
is TRUE
, missing values are removed from the
returned vectors of distinct values. Non-existing rows and columns are
silently ignored.
DataBackendRaster$distinct(rows, cols, na_rm = TRUE)
rows
integer()
Row indices. Row indices start with 1 in the upper left corner in the
raster, increase from left to right and then from top to bottom. The last
cell is in the bottom right corner and the row index equals the number of
cells in the raster.
cols
character()
Column names.
na_rm
logical(1)
Whether to remove NAs or not.
Named list()
of distinct values.
missings()
Returns the number of missing values per column in the specified slice of data. Non-existing rows and columns are silently ignored.
DataBackendRaster$missings(rows, cols)
rows
integer()
Row indices. Row indices start with 1 in the upper left corner in the
raster, increase from left to right and then from top to bottom. The last
cell is in the bottom right corner and the row index equals the number of
cells in the raster.
cols
character()
Column names.
Total of missing values per column (named numeric()
).
coordinates()
Returns the coordinates of rows
.
If rows
is missing, all coordinates are returned.
DataBackendRaster$coordinates(rows)
rows
integer()
Row indices. Row indices start with 1 in the upper left corner in the
raster, increase from left to right and then from top to bottom. The last
cell is in the bottom right corner and the row index equals the number of
cells in the raster.
data.table::data.table()
of coordinates of rows
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.