nearby.RdIdentify geometries that are near to each other. Either get the index of all geometries within a certain distance, or the k nearest neighbors, or (with nearest) get the nearest points between two geometries.
# S4 method for class 'SpatVector'
nearby(x, y=NULL, distance=0, k=1, centroids=TRUE, symmetrical=TRUE, method="geo")
# S4 method for class 'SpatVector'
nearest(x, y, pairs=FALSE, centroids=TRUE, lines=FALSE, method="geo")SpatVector
SpatVector or NULL
numeric. maximum distance
positive integer. number of neighbors. Ignored if distance > 0
logical. Should the centroids of polygons be used?
logical. If TRUE, a near pair is only included once. That is, if geometry 1 is near to geometry 3, the implied nearness between 3 and 1 is not reported. Ignored if k neighbors are returned
character. One of "geo", "haversine", "cosine". With "geo" the most precise but slower method of Karney (2003) is used. The other two methods are faster but less precise
logical. If TRUE pairwise nearest points are returned (only relevant when using at least one SpatVector of lines or polygons
logical. If TRUE lines between the nearest points instead of (the nearest) points
matrix
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
nearby(v, distance=12000)
#> from to
#> [1,] 2 4
#> [2,] 6 8