Skip to content

Commit

Permalink
Merge pull request #1293 from OldLipe/feat/dev-sits
Browse files Browse the repository at this point in the history
Fix vector cube classification with local cubes
  • Loading branch information
OldLipe authored Feb 19, 2025
2 parents 672a615 + 1917f55 commit af82251
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sits
Type: Package
Version: 1.5.2
Version: 1.5.3
Title: Satellite Image Time Series Analysis for Earth Observation Data Cubes
Authors@R: c(person('Rolf', 'Simoes', role = c('aut'), email = '[email protected]'),
person('Gilberto', 'Camara', role = c('aut', 'cre', 'ths'), email = '[email protected]'),
Expand Down
4 changes: 3 additions & 1 deletion R/api_chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ NULL
dplyr::group_by(.data[["id"]]) |>
tidyr::nest() |>
tibble::deframe()
idx_positions <- as.integer(names(idx_intersects))
chunks <- chunks[idx_positions, ]
chunks[["segments"]] <- purrr::map(seq_along(idx_intersects), function(i) {
idx <- unname(as.vector(idx_intersects[[i]]))
idx <- idx[[1]]
Expand All @@ -204,7 +206,7 @@ NULL
output_dir = output_dir,
ext = "gpkg"
)
.vector_write_vec(segments[idx, ], block_file)
.vector_write_vec(segments[idx, ], block_file, append = TRUE)
return(block_file)
})
return(chunks)
Expand Down
6 changes: 6 additions & 0 deletions R/api_classify.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@
n_sam_pol = n_sam_pol,
impute_fn = impute_fn
)
# In some cases, the chunk doesn't have data (e.g., cloudy areas)
if (nrow(segments_ts) == 0) {
return("")
}
# Classify segments
segments_ts <- .classify_ts(
samples = segments_ts,
Expand All @@ -396,6 +400,8 @@
# Return block file
return(block_file)
}, progress = progress)
# Remove empty block files
block_files <- purrr::discard(block_files, Negate(nzchar))
# Read all segments
segments_ts <- purrr::map(block_files, .vector_read_vec)
segments_ts <- dplyr::bind_rows(segments_ts)
Expand Down
8 changes: 7 additions & 1 deletion R/api_segments.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,13 @@
segments <- segments |> dplyr::filter(
.data[["pol_id"]] %in% unique(ts_bands[["polygon_id"]])
)
lat_long <- .proj_to_latlong(segments[["x"]], segments[["y"]], .crs(tile))
if (.has_column(segments, "x") && .has_column(segments, "y")) {
lat_long <- .proj_to_latlong(segments[["x"]], segments[["y"]], .crs(tile))
} else {
lat_long <- tibble::tibble("longitude" = rep(0, nrow(segments)),
"latitude" = rep(0, nrow(segments)))
}

# create metadata for the polygons
samples <- tibble::tibble(
longitude = lat_long[, "longitude"],
Expand Down

0 comments on commit af82251

Please sign in to comment.