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

nearby

nearby geometries


Description

Identify 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 closest points between two geometries.

Usage

## S4 method for signature 'SpatVector'
nearby(x, distance=0, k=1, centroids=TRUE, symmetrical=TRUE)

## S4 method for signature 'SpatVector'
nearest(x, y, pairs=FALSE, centroids=TRUE, lines=FALSE)

Arguments

x

SpatVector

y

SpatVector

distance

numeric. maximum distance

k

positive integer. number of neighbors. Ignored if distance > 0

centroids

logical. Should the centroids of polygons be used?

symmetrical

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

pairs

logical. If TRUE pairwise nearest points are returned (only relevant when using at least one SpatVector of lines or polygons

lines

logical. If TRUE lines between the nearest points instead of (the nearest) points

Value

matrix

See Also

Examples

f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
nearby(v, distance=12000)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

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