Skip to content

Commit

Permalink
* Fixes option of creating spatial lsp objects when the window size…
Browse files Browse the repository at this point in the history
… is 0
  • Loading branch information
Nowosad committed Apr 14, 2024
1 parent d3e820a commit ba845f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
6 changes: 4 additions & 2 deletions R/lsp_add_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-lsp_add_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit ba845f8

Please sign in to comment.