diff --git a/DESCRIPTION b/DESCRIPTION index cbf13964c..f31a88861 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: landscapemetrics Title: Landscape Metrics for Categorical Map Patterns -Version: 2.1.3 +Version: 2.1.4 Authors@R: c(person("Maximilian H.K.", "Hesselbarth", role = c("aut", "cre"), email = "mhk.hesselbarth@gmail.com", @@ -76,5 +76,5 @@ Encoding: UTF-8 LazyData: true Config/testthat/edition: 3 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 65b036d38..0b7489492 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +S3method(landscape_as_list,PackedSpatRaster) S3method(landscape_as_list,RasterBrick) S3method(landscape_as_list,RasterLayer) S3method(landscape_as_list,RasterStack) diff --git a/NEWS.md b/NEWS.md index e572c201d..f18ec06d0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# landscapemetrics 2.1.4 +* Various + * Adding `landscape_as_list()` method for `PackedSpatRaster` + # landscapemetrics 2.1.3 * Bugfixes * Fixed bug in `get_centroids()` related to the patch id diff --git a/R/landscape_as_list.R b/R/landscape_as_list.R index 1af5fa688..485147fb0 100644 --- a/R/landscape_as_list.R +++ b/R/landscape_as_list.R @@ -18,6 +18,7 @@ landscape_as_list <- function(landscape) UseMethod("landscape_as_list") #' @name landscape_as_list #' @export landscape_as_list.SpatRaster <- function(landscape) { + landscape <- terra::as.list(landscape) return(landscape) @@ -87,3 +88,16 @@ landscape_as_list.numeric <- function(landscape) { return(landscape) } + +#' @name landscape_as_list +#' @export +landscape_as_list.PackedSpatRaster <- function(landscape) { + + landscape <- terra::unwrap(landscape) + landscape <- terra::as.list(landscape) + + warning("Unwrapped Packed* input object.", call. = FALSE) + + return(landscape) + +} diff --git a/codemeta.json b/codemeta.json index 37a9e005b..0585c73e5 100644 --- a/codemeta.json +++ b/codemeta.json @@ -7,13 +7,13 @@ "codeRepository": "https://r-spatialecology.github.io/landscapemetrics/", "issueTracker": "https://github.com/r-spatialecology/landscapemetrics/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "2.1.3", + "version": "2.1.4", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", "url": "https://r-project.org" }, - "runtimePlatform": "R version 4.4.0 (2024-04-24)", + "runtimePlatform": "R version 4.4.1 (2024-06-14)", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -303,7 +303,7 @@ }, "SystemRequirements": null }, - "fileSize": "1743.581KB", + "fileSize": "1746.291KB", "citation": [ { "@type": "ScholarlyArticle", diff --git a/cran-comments.md b/cran-comments.md index efa49ea4e..01486af3c 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,7 +1,10 @@ +# landscapemetrics 2.1.4 +Minor feature improvments + # landscapemetrics 2.1.3 -* Improve documentation and minor bugfixes * This is a re-submission. The below error has now been fixed `Please provide package anchors for all Rd \link{} targets` +* Improve documentation and minor bugfixes # landscapemetrics 2.1.2 Minor bugfixes diff --git a/man/landscape_as_list.Rd b/man/landscape_as_list.Rd index 9ae380cc2..ed3591824 100644 --- a/man/landscape_as_list.Rd +++ b/man/landscape_as_list.Rd @@ -10,6 +10,7 @@ \alias{landscape_as_list.list} \alias{landscape_as_list.matrix} \alias{landscape_as_list.numeric} +\alias{landscape_as_list.PackedSpatRaster} \title{Landscape as list} \usage{ landscape_as_list(landscape) @@ -29,6 +30,8 @@ landscape_as_list(landscape) \method{landscape_as_list}{matrix}(landscape) \method{landscape_as_list}{numeric}(landscape) + +\method{landscape_as_list}{PackedSpatRaster}(landscape) } \arguments{ \item{landscape}{A categorical raster object: SpatRaster; Raster* Layer, Stack, Brick; stars or a list of SpatRasters} diff --git a/tests/testthat/test-landscape_as_list.R b/tests/testthat/test-landscape_as_list.R index ee9bc8bf3..871c85dbd 100644 --- a/tests/testthat/test-landscape_as_list.R +++ b/tests/testthat/test-landscape_as_list.R @@ -3,5 +3,6 @@ test_that("landscape_as_list returns a list", { expect_type(landscape_as_list(landscape_stack), "list") expect_type(landscape_as_list(landscape_list), "list") expect_type(landscape_as_list(landscape_matrix), "list") + expect_type(landscape_as_list(terra::wrap(landscape)), "list") })