Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update api_segments to handle empty segments #1155

Merged
merged 8 commits into from
Jun 14, 2024
Prev Previous commit
Next Next commit
Fix segmentation with NA values
  • Loading branch information
OldLipe committed Jun 14, 2024
commit 6717fac12c01f1694262ebff78ad843e203311bf
2 changes: 0 additions & 2 deletions R/api_segments.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
block = block,
impute_fn = impute_fn
)
# Fill with zeros remaining NA pixels
values <- C_fill_na(values, 0)
# Apply segmentation function
values <- seg_fn(values, block, bbox)
# Check if the result values is a vector object
Expand Down
4 changes: 3 additions & 1 deletion R/sits_segmentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ sits_slic <- function(data = NULL,
# Get valid centers
valid_centers <- slic[[2]][, 1] != 0 | slic[[2]][, 2] != 0
# Bind valid centers with segments table
v_obj <- cbind(v_obj, stats::na.omit(slic[[2]][valid_centers, ]))
v_obj <- cbind(
v_obj, matrix(stats::na.omit(slic[[2]][valid_centers, ]), ncol = 2)
)
# Rename columns
names(v_obj) <- c("supercells", "x", "y", "geometry")
# Get the extent of template raster
Expand Down