Skip to contents

mlr3::DataBackend for terra::SpatRaster raster objects.

Read mode

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.

Super class

mlr3::DataBackend -> DataBackendRaster

Active bindings

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.

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage

Arguments


Method 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.

Usage

DataBackendRaster$data(rows, cols, data_format = "data.table")

Arguments

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.


Method head()

Retrieve the first n rows.

Usage

DataBackendRaster$head(n = 6L)

Arguments

n

(integer(1))
Number of rows.

Returns

data.table::data.table() of the first n rows.


Method 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.

Usage

DataBackendRaster$distinct(rows, cols, na_rm = TRUE)

Arguments

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.

Returns

Named list() of distinct values.


Method missings()

Returns the number of missing values per column in the specified slice of data. Non-existing rows and columns are silently ignored.

Usage

DataBackendRaster$missings(rows, cols)

Arguments

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.

Returns

Total of missing values per column (named numeric()).


Method coordinates()

Returns the coordinates of rows. If rows is missing, all coordinates are returned.

Usage

DataBackendRaster$coordinates(rows)

Arguments

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.

Returns

data.table::data.table() of coordinates of rows.