Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get_nearestneighbour

get_nearestneighbour


Description

Euclidean distance to nearest neighbour

Usage

get_nearestneighbour(landscape, return_id)

## S3 method for class 'RasterLayer'
get_nearestneighbour(landscape, return_id = FALSE)

## S3 method for class 'RasterStack'
get_nearestneighbour(landscape, return_id = FALSE)

## S3 method for class 'RasterBrick'
get_nearestneighbour(landscape, return_id = FALSE)

## S3 method for class 'stars'
get_nearestneighbour(landscape, return_id = FALSE)

## S3 method for class 'list'
get_nearestneighbour(landscape, return_id = FALSE)

Arguments

landscape

RasterLayer 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.

References

Based on RCpp code of Florian Privé florian.prive.21@gmail.com

Examples

# get patches for class 1
class_1 <- get_patches(landscape, class = 2)[[1]]

# calculate the distance between patches
get_nearestneighbour(class_1)
get_nearestneighbour(class_1, return_id = TRUE)

landscapemetrics

Landscape Metrics for Categorical Map Patterns

v1.5.2
GPL-3
Authors
Maximillian H.K. Hesselbarth [aut, cre] (<https://orcid.org/0000-0003-1125-9918>), Marco Sciaini [aut] (<https://orcid.org/0000-0002-3042-5435>), Jakub Nowosad [aut] (<https://orcid.org/0000-0002-1057-3721>), Sebastian Hanss [aut] (<https://orcid.org/0000-0002-3990-4897>), Laura J. Graham [ctb] (Input on package structure), Jeffrey Hollister [ctb] (Input on package structure), Kimberly A. With [ctb] (Input on package structure), Florian Privé [ctb] (Original author of underlying C++ code for get_nearestneighbour() function), Project Nayuki [ctb] (Original author of underlying C++ code for get_circumscribingcircle and lsm_p_circle), Matt Strimas-Mackey [ctb] (Bugfix in sample_metrics())
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.