From a6d260a0a3b5fce6ad53f02c9d90285263e1ca1d Mon Sep 17 00:00:00 2001 From: sjevelazco Date: Mon, 13 May 2024 16:28:41 -0300 Subject: [PATCH] calib_area was speeded up --- NAMESPACE | 1 + R/calib_area.R | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 94f08a70..187b81bb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -158,6 +158,7 @@ importFrom(terra,freq) importFrom(terra,geom) importFrom(terra,global) importFrom(terra,is.factor) +importFrom(terra,is.related) importFrom(terra,lapp) importFrom(terra,levels) importFrom(terra,mask) diff --git a/R/calib_area.R b/R/calib_area.R index a0debd64..2c8be00f 100644 --- a/R/calib_area.R +++ b/R/calib_area.R @@ -22,7 +22,7 @@ #' #' @importFrom grDevices chull #' @importFrom methods as is -#' @importFrom terra vect buffer aggregate union crs extract +#' @importFrom terra vect buffer aggregate union crs extract is.related #' #' @examples #' \dontrun{ @@ -210,8 +210,9 @@ calib_area <- function(data, x, y, method, groups = NULL, crs = NULL) { data <- data[, c("x", "y")] data_sp <- data data_sp <- terra::vect(data_sp, geom = names(data_sp), crs = terra::crs(polyc)) - result <- terra::extract(polyc, data_sp)[, cname] %>% unique() - result <- polyc[polyc[[cname]][, 1] %in% result, ] + + result <- polyc[terra::is.related(polyc, data_sp, "intersects"), cname] + # result <- polyc[polyc[[cname]][, 1] %in% result, ] } return(result) }