region: Report or change the extent, dimensions, and/or resolution of...

.region,missing-methodR Documentation

Report or change the extent, dimensions, and/or resolution of a region GRASS

Description

These functions either change the extent, dimensions, and/or resolution of a GRASS "region" or report the current region's extent, dimensions, and/or resolution (see vignette("regions", package = "fasterRaster")). These functions are mostly used internally and rarely of interest to most users.

  • .region(): All 2D and 3D aspects of a region.

  • .regionDim(): x- and y-dimensions.

  • .regionExt(): x- and y-extent.

  • .regionRes(): x- and y-resolution.

Usage

## S4 method for signature 'missing'
.region(x)

## S4 method for signature 'SpatRaster'
.region(x)

## S4 method for signature 'GRegion'
.region(x)

## S4 method for signature 'GRaster'
.region(x, trim = NULL)

## S4 method for signature 'GVector'
.region(x)

## S4 method for signature 'missing'
.regionExt(x)

## S4 method for signature 'numeric'
.regionExt(x, respect)

## S4 method for signature 'GSpatial'
.regionExt(x, respect)

## S4 method for signature 'missing'
.regionDim(x)

## S4 method for signature 'numeric'
.regionDim(x, respect)

## S4 method for signature 'GRegion'
.regionDim(x, respect)

## S4 method for signature 'missing'
.regionRes(x)

## S4 method for signature 'numeric'
.regionRes(x, respect)

## S4 method for signature 'GRegion'
.regionRes(x, respect)

Arguments

x

Any of:

  • Missing (default): Reports the extent, resolution, and dimensions of the current region. All other arguments will be ignored. You can also use ext(), dim(), and res() and related functions with missing arguments.

  • A GSpatial, GRegion, GRaster, GVector object: Sets the region"s extent, dimensions, and/or resolution to those of the object.

  • A numeric vector. This will resize the region's extent, resample the region's resolution/dimensions, or both, to ensure the desired dimensions or resolution are retained: * 2 values for .regionDim(): Number of rows and columns * 4 values for .regionExt(): Westernmost and easternmost easting (longitude), and southernmost and northernmost northing (latitude) * 2 values for .regionRes(): Size of cells in the x- and y-dimensions

trim

A GRaster or NULL (default). If a GRaster, then the region will be trimmed to the non-NA cells in this raster. trim can only be non-NULL if x is a GRaster. Ignored if NULL.

respect

Character or GRaster: Indicates what aspect(s) of the current region to retain. Different functions allow for different aspect to be retained. Partial matching is used.

  • .regionDim(): "extent" or "resolution".

  • .regionExt(): "dimensions" or "resolution".

  • .regionRes(): "extent" or "dimensions". Alternatively, a GRaster can be supplied:

  • .regionDim(): New region will have same extent and resolution.

  • .regionExt(): New region will have same dimensions and resolution.

  • .regionRes(): New region will have same extent and dimensions.

In this case, the new region"s registration will be the same as this raster, and cell resolution will be the same

Note: In most cases extent cannot be retained exactly if the resolution is changed. When resolution is changed, the actual extent will be the user-supplied extent expanded by zero to one rows or zero to one columns to accommodate an integer number of cells of the desired size. The western and northern limits of the extent will be retained, while the eastern and southern limits of the extent will be moved to accommodate an integer number of columns and rows.

Details

When resizing extent, terra keeps the xmin (west) and ymax (north) the fixed and shifts xmax (east) and ymin (south) as needed. To retain as much fidelity between fasterRaster and terra as possible, these functions do the same to the region.

Value

The value returned depends on how the function is used:

  • If used with no arguments, .region() returns a GRegion object.

  • If used with no arguments, .regionDim(), .regionExt(), and .regionRes() return numeric or integer vectors.

  • If the function is used to change reshape/resample the region, it returns a GRegion object reflecting the region before it was changed. This allows users to revert to the original region if desired.

Examples

if (grassStarted()) {

# Setup
library(terra)

# Example data
madElev <- fastData("madElev")
madRivers <- fastData("madRivers")

# Report information on current region:
dim3d()
nrow()
ncol()
ndepth()
ncell()
ncell3d()

ext()
W()
E()
S()
N()

res()
res3d()
xres()
yres()
zres()


}

adamlilith/fasterRaster documentation built on Oct. 26, 2024, 4:06 p.m.