Learn R Programming

terra (version 1.9-25)

thin: 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 SpatVector
thin(x, d, unit="m")

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

Value

SpatVector

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)

See Also

densify, distance, nearby, nearest

Examples

Run this code
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)

Run the code above in your browser using DataLab