From ae5858cd472e6fa265c65aec49cb1aa364b0fec7 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 8 Jun 2024 00:50:26 +0000 Subject: [PATCH 1/2] update segment code --- R/api_segments.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/api_segments.R b/R/api_segments.R index 129308677..2d43e7607 100755 --- a/R/api_segments.R +++ b/R/api_segments.R @@ -265,7 +265,8 @@ x = segments, y = data, by = c(pol_id = "polygon_id") - ) + ) |> + dplyr::filter(.data[["pol_id"]] %in% unique(data[["polygon_id"]])) } #' #' @name .segments_data_read From 34a788d0b8c3581bf7620a3b5c96317a6c242d14 Mon Sep 17 00:00:00 2001 From: Felipe Carlos Date: Sat, 8 Jun 2024 19:18:29 -0300 Subject: [PATCH 2/2] fix chunks-segments intersection --- R/api_chunks.R | 14 +++++++++++--- R/zzz.R | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/R/api_chunks.R b/R/api_chunks.R index c3229b9ba..ea3ed6371 100644 --- a/R/api_chunks.R +++ b/R/api_chunks.R @@ -166,9 +166,17 @@ NULL .bbox(chunks, by_feature = TRUE, default_crs = .tile_crs(tile)) ) # Find segments in chunks - idx_contains <- sf::st_contains(sf_chunks, segments, sparse = TRUE) - chunks[["segments"]] <- purrr::map(seq_along(idx_contains), function(i) { - idx <- idx_contains[[i]] + idx_intersects <- sf::st_intersects(sf_chunks, segments, sparse = TRUE) |> + purrr::imap_dfr( + ~dplyr::as_tibble(.x) |> dplyr::mutate(id = .y) + ) |> + dplyr::distinct(.data[["value"]], .keep_all = TRUE) |> + dplyr::group_by(.data[["id"]]) |> + tidyr::nest() |> + tibble::deframe() + chunks[["segments"]] <- purrr::map(seq_along(idx_intersects), function(i) { + idx <- unname(as.vector(idx_intersects[[i]])) + idx <- idx[[1]] block_file <- .file_block_name( pattern = "chunk_seg", block = .block(chunks[i, ]), diff --git a/R/zzz.R b/R/zzz.R index 5653ca686..af3508797 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -21,7 +21,7 @@ sits_env <- new.env() sits_env[["model_formula"]] <- "log" # Include the following global variables in the sits package utils::globalVariables(c( - ".x", ":=", # dplyr + ".x", ".y", ":=", # dplyr "self", "ctx", "super", "private", # torch "uniform", "choice", "randint", "normal", "lognormal", "loguniform", # sits_tuning_random