preview_gd: Preview moving window and sample counts

View source: R/preview_gd.R

preview_gdR Documentation

Preview moving window and sample counts

Description

Generate a preview of moving window size and sample counts based on the coordinates and parameters to be supplied to window_gd, circle_gd, or resist_gd. The method to be used should be specified with method = "window", "circle", or "resist". For method = "window", wdim must be specified. For method = "circle" or "resist", maxdist must be specified and distmat can also optionally be specified.

Usage

preview_gd(
  lyr,
  coords,
  method = "window",
  wdim = 3,
  maxdist = NULL,
  distmat = NULL,
  fact = 0,
  sample_count = TRUE,
  min_n = 0,
  plot = TRUE
)

Arguments

lyr

SpatRaster or RasterLayer to slide the window across (see Details for important information about projections). For method = "resist" this should also be the conductivity layer (see resist_gd)

coords

coordinates of samples as sf points, a two-column matrix, or a data.frame representing x and y coordinates (see Details for important information about projections)

method

which method to use to create preview ("window" for window_gd, "circle" for circle_gd, or "resist" for resist_gd; defaults to "window")

wdim

if method = "window", dimensions (height x width) of window; if only one value is provided, a square window is created (defaults to 3 x 3 window)

maxdist

if method = "circle" or ⁠method = "resist⁠, the maximum geographic distance used to define the neighborhood; any samples further than this distance will not be included (see get_geodist or get_resdist)

distmat

if method = "circle" or method = "resist", an optional distance matrix to be used output from either get_geodist or get_resdist, respectively. If not provided, one will be automatically calculated.

fact

aggregation factor to apply to lyr (defaults to 0; note: increasing this value reduces computational time)

sample_count

whether to create plot of sample counts for each cell (defaults to TRUE)

min_n

minimum number of samples to use in calculations (any focal cell with a window containing less than this number of samples will be assigned a value of NA)

plot

whether to plot results (default = TRUE)

Details

Coordinates and rasters should be in a projected (planar) coordinate system such that raster cells are of equal sizes. Therefore, spherical systems (including latitute-longitude coordinate systems) should be projected prior to use. Transformation can be performed using st_set_crs for coordinates or project for rasters (see vignette for more details).

Value

Plots preview of window and returns SpatRaster with sample counts layer (if sample_count = TRUE)

Examples

load_mini_ex()
preview_gd(mini_lyr, mini_coords, wdim = 3, fact = 3, sample_count = TRUE, min_n = 2)

wingen documentation built on May 29, 2024, 9:59 a.m.