Region: R6 class representing a study region.

RegionR Documentation

R6 class representing a study region.

Description

R6 class representing a study region of spatial grid cells defined via a list of longitude/latitude cell coordinates (WGS84), or a RasterLayer object (see raster).

Super class

poems::GenericClass -> Region

Public fields

attached

A list of dynamically attached attributes (name-value pairs).

Active bindings

coordinates

Data frame (or matrix) of X-Y population (WGS84) coordinates in longitude (degrees West) and latitude (degrees North) (get and set), or distance-based coordinates dynamically returned by region raster (get only).

region_raster

A RasterLayer object (see raster) defining the region with finite values (NAs elsewhere).

use_raster

Boolean to indicate that a raster is to be used to define the region (default TRUE).

strict_consistency

Boolean to indicate that, as well as resolution, extent and CRS, consistency checks also ensure that a raster's finite/occupiable cells are the same or a subset of those defined by the region (default TRUE).

region_cells

Dynamically calculated number of region coordinates or raster cells with finite/non-NA values.

region_indices

Dynamically calculated region indices for raster cells with finite/non-NA values (all if not a raster).

Methods

Public methods

Inherited methods

Method new()

Initialization method sets coordinates or raster for region.

Usage
Region$new(
  coordinates = NULL,
  template_raster = NULL,
  region_raster = NULL,
  use_raster = TRUE,
  ...
)
Arguments
coordinates

Data frame (or matrix) of X-Y coordinates (WGS84) in longitude (degrees West) and latitude (degrees North).

template_raster

A RasterLayer object (see raster) defining the region with example finite values (NAs elsewhere)

region_raster

A RasterLayer object (see raster) defining the region with finite cell indices (NAs elsewhere).

use_raster

Boolean to indicate that a raster is to be used to define the region (default TRUE).

...

Additional parameters passed individually.


Method raster_is_consistent()

Returns a boolean to indicate if a raster is consistent with the region raster (matching extent, resolution, and finite/NA cells).

Usage
Region$raster_is_consistent(check_raster)
Arguments
check_raster

A RasterLayer, RasterStack or RasterBrick object (see raster) to check for consistency with the region raster.

Returns

Boolean to indicate if the raster is consistent with the region raster.


Method raster_from_values()

Converts an array (or matrix) of values into a raster (or stack) consistent with the region raster (matching extent, resolution, and finite/NA cells).

Usage
Region$raster_from_values(values)
Arguments
values

An array (or matrix) of values to be placed in the raster (or stack) having dimensions consistent with the region cell number.

Returns

A RasterLayer (or RasterStack/Brick) object consistent with the region raster.


Method clone()

The objects of this class are cloneable with this method.

Usage
Region$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# U Island example region
coordinates <- data.frame(x = rep(seq(177.01, 177.05, 0.01), 5),
                          y = rep(seq(-18.01, -18.05, -0.01), each = 5))
template_raster <- Region$new(coordinates = coordinates)$region_raster # full extent
template_raster[][-c(7, 9, 12, 14, 17:19)] <- NA # make U Island
region <- Region$new(template_raster = template_raster)
raster::plot(region$region_raster, main = "Example region (cell indices)",
             xlab = "Longitude (degrees)", ylab = "Latitude (degrees)",
             colNA = "blue")
region$region_cells
region$coordinates
# Generate value layers
value_brick <- region$raster_from_values(array(8:28, c(7, 3)))
raster::plot(value_brick, main = "Example value layers",
             xlab = "Longitude (degrees)", ylab = "Latitude (degrees)",
             colNA = "blue")
value_brick[region$region_indices]


poems documentation built on Oct. 7, 2023, 9:06 a.m.