Skip to contents

RasterAggregate: block statistics as terra::aggregate (partial edge blocks kept). RasterDisaggregate: nearest-value split. RasterResample: bilinear or nearest values at points. ZonalStatistics: statistic per zone. RasterMask: as terra::mask. DistanceTransform: Euclidean distance to the nearest non-NA cell. CostDistance: accumulated least cost with 8 neighbours (mean friction times step length, the ArcGIS Cost Distance and gdistance convention).

Usage

RasterAggregate(grid, fact, fun = "mean", na_rm = FALSE)

RasterDisaggregate(grid, fact)

RasterResample(grid, extent, new_x, new_y, method = "bilinear")

ZonalStatistics(grid, zones, fun = "mean")

RasterMask(grid, mask, maskvalue = NULL, inverse = FALSE)

DistanceTransform(grid, res = 1)

CostDistance(cost, sources, res = 1)

Arguments

grid, zones, mask, cost

Numeric matrices (row 1 = north).

fact

Aggregation factor.

fun

Statistic.

na_rm

Drop NA values.

extent

c(xmin, xmax, ymin, ymax) of the source grid.

new_x, new_y

Target coordinates.

method

"bilinear" or "near".

maskvalue

Value treated as masked.

inverse

Invert the mask.

res

Cell size.

sources

Two-column matrix of source (row, column) cells.

Value

Matrix or list.

References

Hijmans, R. J. (2024). terra: Spatial Data Analysis. R package.

Examples

RasterAggregate(matrix(1:9, 3, byrow = TRUE), 2)
#>      [,1] [,2]
#> [1,]  3.0  4.5
#> [2,]  7.5  9.0
CostDistance(rbind(c(1, 1, 1), c(1, 9, 1), c(1, 1, 1)), cbind(1, 1))[3, 3]
#> [1] 3.414214