R/selectHigh.R

setMethod("selectHighest", signature(x="SpatRaster"),
	function(x, n, low=FALSE) {
		x <- x[[1]]
		n <- min(ncell(x), max(1, n))
		i <- order(values(x, mat=FALSE), decreasing=!low)[1:n]
		x <- rast(x)
		x[i] <- 1
		x
	}
)

Try the terra package in your browser

Any scripts or data that you put into this service are public.

terra documentation built on Oct. 13, 2023, 5:08 p.m.