diff --git a/R/rasterCVA.R b/R/rasterCVA.R index c868812..a14c1a1 100644 --- a/R/rasterCVA.R +++ b/R/rasterCVA.R @@ -21,6 +21,7 @@ #' Returns a SpatRaster with two layers: change vector angle and change vector magnitude #' @export #' @examples +#' \donttest{ #' library(terra) #' pca <- rasterPCA(lsat)$map #' @@ -28,6 +29,7 @@ #' cva <- rasterCVA(pca[[1:2]], pca[[3:4]]) #' cva #' plot(cva) +#' } rasterCVA <- function(x, y, tmf = NULL, nct = NULL, ...) { x <- .toTerra(x) y <- .toTerra(y) @@ -96,7 +98,7 @@ rasterCVA <- function(x, y, tmf = NULL, nct = NULL, ...) { nct <- tmf * medianEstimate rm(RStoolbox_rasterCVAEnv) } - out <- terra::clamp(out, lower = nct, ... = ellips) + out <- do.call(terra::clamp, c(list(x = out, lower=nct), ellips)) names(out) <- c("angle", "magnitude") } @@ -104,20 +106,3 @@ rasterCVA <- function(x, y, tmf = NULL, nct = NULL, ...) { return(out) } -test <- function(){ - devtools::load_all() - - r <- rast(val = 0, ncol = 2, nrow = 10) - r1 <- r2 <- c(r, r) - s <- 4 - x <- c(0,s,s,s,0,-s,-s,-s, NA, 0) - y <- c(s,s,0,-s,-s,-s,0,s, 0, NA) - r2[[1]][] <- c(x, x + sign(x)*2) - r2[[2]][] <- c(y, y + sign(y)*2) - - expectedDf <- as.matrix(data.frame(angle = c(0,45,90,135,180,225,270,315,NA,NA), - magnitude = c(rep(c(s, sqrt(2*s^2)), 4), NA,NA, rep(c((2+s), sqrt(2*(2+s)^2)), 4), NA,NA))) - - rasterCVA(r1,r2, tmf = 0) - -} diff --git a/R/rasterPCA.R b/R/rasterPCA.R index 0ddbe1d..eee04aa 100644 --- a/R/rasterPCA.R +++ b/R/rasterPCA.R @@ -24,6 +24,7 @@ #' @return Returns a named list containing the PCA model object ($model) and a SpatRaster with the principal component layers ($object). #' @export #' @examples +#' \donttest{ #' library(ggplot2) #' library(reshape2) #' ggRGB(rlogo, 1,2,3) @@ -42,6 +43,7 @@ #' plots <- lapply(1:3, function(x) ggR(rpc$map, x, geom_raster = TRUE)) #' grid.arrange(plots[[1]],plots[[2]], plots[[3]], ncol=2) #' } +#' } rasterPCA <- function(img, nSamples = NULL, nComp = nlyr(img), spca = FALSE, maskCheck = TRUE, ...){ img <- .toTerra(img) diff --git a/man/rasterCVA.Rd b/man/rasterCVA.Rd index 7ef16da..a832124 100644 --- a/man/rasterCVA.Rd +++ b/man/rasterCVA.Rd @@ -33,6 +33,7 @@ For example for a given pixel in image A and B for the red and nir band the chan Angles are returned *in degree* beginning with 0 degrees pointing 'north', i.e. the y-axis, i.e. the second band. } \examples{ +\donttest{ library(terra) pca <- rasterPCA(lsat)$map @@ -41,3 +42,4 @@ cva <- rasterCVA(pca[[1:2]], pca[[3:4]]) cva plot(cva) } +} diff --git a/man/rasterPCA.Rd b/man/rasterPCA.Rd index 6e94307..c2333d7 100644 --- a/man/rasterPCA.Rd +++ b/man/rasterPCA.Rd @@ -47,6 +47,7 @@ Standardised PCA (SPCA) can be useful if imagery or bands of different dynamic r has the same effect as using normalised bands of unit variance. } \examples{ +\donttest{ library(ggplot2) library(reshape2) ggRGB(rlogo, 1,2,3) @@ -66,3 +67,4 @@ if(require(gridExtra)){ grid.arrange(plots[[1]],plots[[2]], plots[[3]], ncol=2) } } +}