Skip to content

Commit

Permalink
for #1314
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 27, 2023
1 parent aa0060d commit 1a16fc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/k_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setMethod("k_means", signature(x="SpatRaster"),
function(x, centers=3, ..., maxcell=1000000, filename="", overwrite=FALSE, wopt=list()) {
stopifnot(maxcell > 0)
if (ncell(x) <= maxcell) {
v <- values(x)
v <- na.omit(values(x))
omit <- as.vector(attr(v, "na.action"))
km <- stats::kmeans(v, centers=centers, ...)
out <- rast(x, nlyr=1)
Expand Down
9 changes: 9 additions & 0 deletions inst/tinytest/test_multivariate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

f <- system.file("ex/logo.tif", package = "terra")
r <- rast(f)
km <- k_means(r, centers=5)
r[1] <- NA
km <- k_means(r, centers=5)
km <- k_means(r, centers=5, maxcell=10)


0 comments on commit 1a16fc7

Please sign in to comment.