# get patches for class 1
landscape <- terra::rast(landscapemetrics::landscape)
class_1 <- get_patches(landscape, class = 2)[[1]][[1]]
# calculate the distance between patches
get_nearestneighbour(class_1)
get_nearestneighbour(class_1, return_id = TRUE)
Run the code above in your browser using DataLab