rasters_moving_cor {lidaRtRee}R Documentation

Correlation between rasters for different XY translations

Description

computes correlation between two rasters for different XY translations. The correlation values are computed on the extent of the smallest raster using rasters2Cor, after applying an optional mask, and for each translation within a buffer area.

Usage

rasters_moving_cor(raster_b, raster_s, mask = NULL, buffer = 19, step = 0.5)

Arguments

raster_b

SpatRaster. raster to correlate with largest extent

raster_s

SpatRaster. raster to correlate with smallest extent

mask

SpatRaster. mask of area to correlate, applied to small raster

buffer

numeric. radius of the circular buffer area for possible translations

step

numeric. increment step of translations within buffer area to compute correlation values, should be a multiple of raster resolution

Value

A SpatRaster. Raster value at coordinates x,y correspond to the correlation between the large raster and the small raster when small raster center has been translated of (x,y)

See Also

raster_local_max to extract local maximum of resulting correlation raster, rasters2Cor

Examples

# create raster
r_b <- terra::rast(xmin = 0, xmax = 40, ymin =0 , ymax = 40,
resolution = 1, crs = NA)
xy <- terra::xyFromCell(r_b, 1:(nrow(r_b) * ncol(r_b)))

# add Gaussian surfaces
z1 <- 1.5 * exp(-((xy[, 1] - 22)^2 + (xy[, 2] - 22)^2 / 2) / 5)
z2 <- exp(-((xy[, 1] - 20)^2 + (xy[, 2] - 22)^2 / 2) / 3)
z3 <- 1.5 * exp(-((xy[, 1] - 17)^2 + (xy[, 2] - 17)^2 / 2) / 5)
r_b <- terra::rast(cbind(xy, z1 + z2 + z3), type = "xyz")

# create small raster
r_s <- terra::crop(r_b, terra::ext(c(15, 25, 15, 25)))
# offset raster by (-2, -2)
terra::ext(r_s) <- c(13, 23, 13, 23)

# compute correlations for translations inside buffer
rr <- rasters_moving_cor(r_b, r_s, buffer = 6, step = 1)
rr

# display large raster
terra::plot(r_b, main = "Large raster")
# display small raster
terra::plot(r_s, main = "Small raster")
# display correlation
terra::plot(rr,
  xlab = "X translation", ylab = "Y translation",
  main = "Correlation between rasters"
)

[Package lidaRtRee version 4.0.5 Index]