similarity: Similarity

similarityR Documentation

Similarity

Description

Determine for each grid cell the location/record it is most similar to.

Usage

## S4 method for signature 'SpatRaster,SpatVector'
similarity(x, y, labels="", filename="", ...)

## S4 method for signature 'SpatRaster,data.frame'
similarity(x, y, labels="", filename="", ...)

Arguments

x

SpatRaster

y

SpatVector or data.frame

labels

character. labels that correspond to each class (row in y

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

Examples

library(terra)
f <- system.file("ex/logo.tif", package = "terra")
r <- rast(f)

# locations of interest 
pts <- vect(cbind(c(25.25, 34.324, 43.003), c(54.577, 46.489, 30.905)))
pts$code <- LETTERS[1:3]

plot(r)
points(pts, pch=20, cex=2, col="red")
text(pts, "code", pos=4, halo=TRUE)

x <- scale(r)

s1 <- similarity(x, pts, labels=pts$code)
plot(s1)

# same result
e <- extract(x, pts, ID=FALSE)
s2 <- similarity(x, e, labels=c("Ap", "Nt", "Ms"))

rspatial/terra documentation built on April 28, 2024, 12:22 a.m.