diff --git a/NEWS.md b/NEWS.md index a50240964..fcd5b4812 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ - `autocor` improved handling of NA cells for global Moran computation [#1992](https://github.com/rspatial/terra/issues/1592) by Nicholas Berryman - `shade` is more memory-safe. [#1452](https://github.com/rspatial/terra/issues/1452) by Francis van Oordt and Chris English - fixed bug in `rasterize` revealed when using `crop(mask=TRUE)` [#1686](https://github.com/rspatial/terra/issues/1686) by edixon1 +- fixed `to_id = NA` bug in `nearest` [#1471](https://github.com/rspatial/terra/issues/1471) by Mats Blomqvist + ## enhancements diff --git a/R/animate.R b/R/animate.R index 7a2e3609c..ed35d670b 100644 --- a/R/animate.R +++ b/R/animate.R @@ -6,7 +6,8 @@ function(x, pause=0.25, main, range, maxcell=50000, n=1, ...) { main <- names(x) } - x <- spatSample(x, size=maxcell, method="regular", as.raster=TRUE, warn=FALSE) +# x <- spatSample(x, size=maxcell, method="regular", as.raster=TRUE, warn=FALSE) + x <- sampleRaster(x, maxcell, method="regular", replace=FALSE, ext=NULL, warn=FALSE, overview=TRUE) if (missing(range)) { mnmx <- minmax(x) diff --git a/R/coerce.R b/R/coerce.R index 0da9f4aca..b0613bdff 100644 --- a/R/coerce.R +++ b/R/coerce.R @@ -202,6 +202,7 @@ setMethod("as.raster", signature(x="SpatRaster"), #col <- rev(grDevices::terrain.colors(255)) col <- .default.pal() } + x <- spatSample(x, maxcell, method="regular", as.raster=TRUE, warn=FALSE) x <- as.matrix(x, wide=TRUE) r <- range(x, na.rm=TRUE) diff --git a/R/sample.R b/R/sample.R index 71f272cbc..c73bc8eab 100644 --- a/R/sample.R +++ b/R/sample.R @@ -396,7 +396,7 @@ set_factors <- function(x, ff, cts, asdf) { s } -sampleRaster <- function(x, size, method, replace, ext=NULL, warn) { +sampleRaster <- function(x, size, method, replace, ext=NULL, warn, overview=FALSE) { # hadWin <- hasWin <- FALSE if (!is.null(ext)) { # hasWin <- TRUE @@ -413,7 +413,7 @@ sampleRaster <- function(x, size, method, replace, ext=NULL, warn) { if (length(size) > 1) { x@pntr <- x@pntr$sampleRowColRaster(size[1], size[2], warn[1]) } else { - x@pntr <- x@pntr$sampleRegularRaster(size) + x@pntr <- x@pntr$sampleRegularRaster(size, overview) } } else if (method == "random") { x@pntr <- x@pntr$sampleRandomRaster(size, replace, .seed())