diff --git a/DESCRIPTION b/DESCRIPTION index 9f41480..4059509 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ Description: Describes spatial patterns of categorical raster data for License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Depends: R (>= 3.1) LinkingTo: diff --git a/NEWS.md b/NEWS.md index 79823ce..02fe712 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# motif 0.6.4 + +* Fixes option of creating spatial `lsp` objects when the window size is 0 + # motif 0.6.3 * Adds an option to remove metadata information with `lsp_add_stars`, `lsp_add_terra`, and `lsp_add_sf` diff --git a/R/lsp_add_spatial.R b/R/lsp_add_spatial.R index 6a69d65..712e909 100644 --- a/R/lsp_add_spatial.R +++ b/R/lsp_add_spatial.R @@ -104,8 +104,10 @@ lsp_add_stars.lsp = function(x = NULL, window = NULL, metadata = TRUE){ if (metadata_attr$use_window && is.null(window)){ stop("This function requires an sf object in the window argument for irregular local landscapes.", call. = FALSE) } - - if (is.null(window)){ + if (metadata_attr$window_shift == 0){ + output_stars = stars::st_as_stars(metadata_attr$bb, nx = 1, ny = 1, values = 1) + names(output_stars) = "id" + } else if (is.null(window)){ output_stars = lsp_create_grid(x_crs = metadata_attr$crs, x_bb = metadata_attr$bb, x_delta_row = metadata_attr$delta_y, diff --git a/tests/testthat/test-lsp_add_spatial.R b/tests/testthat/test-lsp_add_spatial.R index 562b3f7..776dc70 100644 --- a/tests/testthat/test-lsp_add_spatial.R +++ b/tests/testthat/test-lsp_add_spatial.R @@ -17,10 +17,12 @@ landform_lsp_stars2 = lsp_add_stars(result_coma) landform_lsp_sf4 = lsp_add_sf(result_coma) landform_lsp_stars3 = lsp_add_stars(result_coma, metadata = FALSE) landform_lsp_sf5 = lsp_add_sf(result_coma, metadata = FALSE) +result_coma2 = lsp_signature(landform, type = "cove", threshold = 1) test_that("tests lsp_add_spatial works on lsp", { expect_equal(length(landform_lsp_stars2), 80) expect_equal(length(landform_lsp_stars3), 78) expect_equal(ncol(landform_lsp_sf4), 4) expect_equal(ncol(landform_lsp_sf5), 2) + expect_equal(nrow(result_coma2), 1) })