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) }