From 58b696faebc2e23b91c65d34455ed4fc06e0ecdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darius=20G=C3=B6rgen?= Date: Wed, 6 Dec 2023 11:59:08 +0100 Subject: [PATCH] setting snap to out to crop rasters by default (#212) --- NEWS.md | 1 + R/calc_indicators.R | 2 +- tests/testthat/test-calc_indicator.R | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index ad578b37..e2d0ae5e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ - `calc_indicators()` now includes a check for 0-length tibbles (#199, #216) - .read_raster_source now uses a single logic to cover all cases (e.g. single tiles, tiled rasters with and without temporal dimension, single temporal rasters) +- cropping rasters now uses `snap="out"` by default - .read_raster_source now projects assets in case their CRS differs from the raster diff --git a/R/calc_indicators.R b/R/calc_indicators.R index 733050d6..aaeac2d1 100644 --- a/R/calc_indicators.R +++ b/R/calc_indicators.R @@ -146,7 +146,7 @@ calc_indicators <- function(x, indicators, ...) { out <- do.call(c, out) # crop the source to the extent of the current polygon - cropped <- try(terra::crop(out, terra::vect(x))) + cropped <- try(terra::crop(out, terra::vect(x), snap = "out")) if (inherits(cropped, "try-error")) { warning(as.character(cropped)) return(NULL) diff --git a/tests/testthat/test-calc_indicator.R b/tests/testthat/test-calc_indicator.R index a5eaed70..698a0b3d 100644 --- a/tests/testthat/test-calc_indicator.R +++ b/tests/testthat/test-calc_indicator.R @@ -146,7 +146,7 @@ test_that("Parallelization works", { expect_equal( stat, - c(2603.803, 2600.664, 2596.358, 2557.306, 2540.299, 2532.707), + c(2656.062, 2652.923, 2648.616, 2609.273, 2592.046, 2584.090), tolerance = 1e-3 ) })