thin: Subset geometries by minimum distance

thinR Documentation

Subset geometries by minimum distance

Description

thin return a subset of geometries such that all remaining geometries are at least d apart from each other. This uses greedy spatial thinning: the first geometry is always kept, and subsequent geometries are only kept if they are at least d away from all previously kept geometries.

thinNodes reduces the number of nodes to represent line or polygon geometries

Usage

## S4 method for signature 'SpatVector'
thin(x, d, unit="m")

## S4 method for signature 'SpatVector'
thinNodes(x, d, unit="m", makeValid=TRUE)

Arguments

x

SpatVector

d

positive numeric. The minimum distance between geometries or nodes

unit

character. "m" (meter, the default) or "km" (kilometer)

makeValid

logical. If TRUE an attempt is made to assure that thinned polygon geometries are valid (e.g., not self intersecting)

Value

SpatVector

See Also

densify, distance, nearby, nearest

Examples

p <- vect( matrix(c(0, .5, .6, 5, 5.5, 50), ncol=2, nrow=6), crs="lonlat")
values(p) <- data.frame(id=1:6)
nrow(p)

# points that are at least 200 km apart
p2 <- thin(p, 200000)
nrow(p2)

# same, using km
p3 <- thin(p, 200, unit="km")
nrow(p3)

terra documentation built on Aug. 22, 2026, 5:07 p.m.