diff --git a/R/api_chunks.R b/R/api_chunks.R index c3229b9b..ea3ed637 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/api_segments.R b/R/api_segments.R index 12930867..2d43e760 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 diff --git a/R/zzz.R b/R/zzz.R index 5653ca68..af350879 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