Skip to content

Commit

Permalink
Merge pull request #1152 from M3nin0/fix/seg-intersects
Browse files Browse the repository at this point in the history
fix chunks-segments intersection
  • Loading branch information
gilbertocamara committed Jun 10, 2024
2 parents 5e68f0a + 34a788d commit e0d1ef5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions R/api_chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ]),
Expand Down
3 changes: 2 additions & 1 deletion R/api_segments.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0d1ef5

Please sign in to comment.