Learn R Programming

terra (version 1.8-5)

interpNear: Nearest neighbor interpolation

Description

Nearest neighbor interpolation of points, using a moving window

Usage

# S4 method for SpatRaster,SpatVector
interpNear(x, y, field, radius, interpolate=FALSE, fill=NA, filename="", ...)

# S4 method for SpatRaster,matrix interpNear(x, y, radius, interpolate=FALSE, fill=NA, filename="", ...)

Value

SpatRaster

Arguments

x

SpatRaster

y

SpatVector or matrix with three columns (x,y,z)

field

character. field name in SpatVector y

radius

numeric. The radius of the circle (single number). If interpolate=FALSE it is also possible to use two or three numbers. Two numbers are interpreted as the radii of an ellipse (x and y-axis). A third number should indicated the desired, counter clockwise, rotation of the ellipse (in degrees)

interpolate

logical. Should the nearest neighbor values be linearly interpolated between points?

fill

numeric. value to use to fill empty cells

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

See Also

rasterizeWin, rasterize, interpIDW, interpolate

Examples

Run this code

r <- rast(ncol=100, nrow=100, crs="local", xmin=0, xmax=50, ymin=0, ymax=50)
set.seed(100)
x <- runif(25, 5, 45)
y <- runif(25, 5, 45)
z <- sample(25)
xyz <- cbind(x,y,z)

x <- interpNear(r, xyz, radius=5)

p <- vect(data.frame(xyz), geom=c("x", "y")) 
v <- voronoi(p)

plot(x, col=rainbow(25))
lines(v)

# plot(v, col=rainbow(25)); points(p)

Run the code above in your browser using DataLab