landscape: SpatRaster or matrix (with x,y,id columns).
return_id: If TRUE, also the patch ID of the nearest neighbour is returned.
Details
Fast and memory safe Rcpp implementation for calculating the minimum Euclidean distances to the nearest patch of the same class in a raster or matrix. All patches need an unique ID (see get_patches). Please be aware that the patch ID is not identical to the patch ID of all metric functions (lsm_). If return_ID = TRUE, for some focal patches several nearest neighbour patches might be returned.
Because the metric is based on distances or areas please make sure your data is valid using check_landscape.
Examples
# get patches for class 1landscape <- terra::rast(landscapemetrics::landscape)class_1 <- get_patches(landscape, class =2)[[1]][[1]]# calculate the distance between patchesget_nearestneighbour(class_1)get_nearestneighbour(class_1, return_id =TRUE)