st_knn: Calculate K-Nearest Neighbors

View source: R/neighbors.R

st_knnR Documentation

Calculate K-Nearest Neighbors

Description

Identifies the k nearest neighbors for given point geometry. If polygon geometry is provided, the centroids of the polygon will be used and a warning will be emitted.

Usage

st_knn(geometry, k = 1, symmetric = FALSE, ...)

Arguments

geometry

an sf or sfc object.

k

number of nearest neighbours to be returned

symmetric

default FALSE. Whether to force output of neighbours to be symmetric.

...

additional arguments to be passed to knearneigh().

Details

This function utilizes spdep::knearneigh() and spdep::knn2nb().

Value

a list of class nb

See Also

Other neighbors: st_contiguity(), st_dist_band()

Examples

st_knn(sf::st_geometry(guerry), k = 8)

sfdep documentation built on Sept. 13, 2024, 5:07 p.m.