Generates a SpatRaster of randomly-varying values on the same grid as a template raster x, using a built-in Gaussian-smoothed random field with no extra package dependencies.

neutralLandscapeMap(
  x,
  pad = 10L,
  type = "gaussian",
  smooth = 3L,
  rescale = TRUE,
  ...
)

Arguments

x

A SpatRaster (or RasterLayer) to use as a template for the grid and CRS.

pad

Integer. Number of cells by which to pad x internally; the padding is cropped from the result.

type

Character. Only "gaussian" (the default) is supported.

smooth

Half-width (in cells) of the smoothing kernel; larger values produce smoother landscapes with longer-range autocorrelation.

rescale

If TRUE (default), rescale output values to [0, 1].

...

Currently ignored; accepted for backwards compatibility.

Value

A SpatRaster (or RasterLayer, matching x) with the same extent, resolution, and CRS as x, filled with randomly-generated values.

Details

The "gaussian" generator fills a padded grid with i.i.d. normal noise, then smooths it with a square mean kernel of size 2 * smooth + 1. The result is a roughly Gaussian random field, suitable for sample modules, demos, and tests.

Examples

# \donttest{
  library(terra)
  nx <- ny <- 100L
  r <- rast(nrows = ny, ncols = nx,
            xmin = -nx/2, xmax = nx/2,
            ymin = -ny/2, ymax = ny/2)

  map_default <- neutralLandscapeMap(r)
  if (interactive()) plot(map_default)

  ## Tweak smoothness:
  map_rough  <- neutralLandscapeMap(r, smooth = 1)
  map_smooth <- neutralLandscapeMap(r, smooth = 8)
# }