Learn R Programming

bitfield (version 1.0.0)

bf_encode: Encode bit flags into a bitfield

Description

This function picks up the flags mentioned in a registry and encodes them as integer values.

Usage

bf_encode(registry)

Value

Depending on the registry template type: a data.frame with integer columns (one per 32-bit chunk) if template is a table, or a SpatRaster with integer layers if template is a raster.

Arguments

registry

registry(1)
the registry that should be encoded into a bitfield.

Examples

Run this code
reg <- bf_registry(name = "testBF", description = "test bitfield",
                   template = bf_tbl)
reg <- bf_map(protocol = "na", data = bf_tbl, registry = reg, x = y)

field <- bf_encode(registry = reg)

# with raster data
library(terra)
bf_rst <- rast(nrows = 3, ncols = 3, vals = bf_tbl$commodity, names = "commodity")
bf_rst$yield <- rast(nrows = 3, ncols = 3, vals = bf_tbl$yield)

reg <- bf_registry(name = "testBF", description = "raster bitfield",
                   template = bf_rst)
reg <- bf_map(protocol = "na", data = bf_rst, registry = reg, x = commodity)

field <- bf_encode(registry = reg)  # returns a SpatRaster

Run the code above in your browser using DataLab