Skip to content

Commit 8590399

Browse files
committed
fix sits_merge
1 parent 691a70d commit 8590399

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

R/sits_merge.R

+9-5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ sits_merge.sar_cube <- function(data1, data2, ...) {
105105
dplyr::filter(data2, .data[["tile"]] %in% common_tiles),
106106
.data[["tile"]]
107107
)
108+
if (length(.cube_timeline(data2)[[1]]) == 1){
109+
return(.merge_single_timeline(data1, data2))
110+
}
108111
if (inherits(data2, "sar_cube")) {
109112
return(.merge_equal_cube(data1, data2))
110113
} else {
@@ -131,10 +134,9 @@ sits_merge.raster_cube <- function(data1, data2, ...) {
131134
dplyr::filter(data2, .data[["tile"]] %in% common_tiles),
132135
.data[["tile"]]
133136
)
134-
if (length(.cube_timeline(data2)) == 1){
137+
if (length(.cube_timeline(data2)[[1]]) == 1){
135138
return(.merge_single_timeline(data1, data2))
136139
}
137-
138140
if (inherits(data2, "sar_cube")) {
139141
return(.merge_distinct_cube(data1, data2))
140142
} else {
@@ -200,12 +202,14 @@ sits_merge.raster_cube <- function(data1, data2, ...) {
200202
# Return cubes merged
201203
return(data1)
202204
}
205+
203206
.merge_single_timeline <- function(data1, data2){
204207
# Get data1 timeline
205208
d1_tl <- unique(as.Date(.cube_timeline(data1)[[1]]))
206-
fi_new <- purrr::map_chr(sits_timeline(data1), function(d){
207-
fi <- .fi(data2)
208-
fi[["date"]] <- as.Date(d)
209+
fi_new <- purrr::map(1:nrow(data2), function(idx) {
210+
d <- data2[idx,]
211+
fi <- .fi(data2[idx,])
212+
fi[["date"]] <- as.Date(d1_tl[1:nrow(d)])
209213
return(fi)
210214
})
211215
data2[["file_info"]] <- fi_new

0 commit comments

Comments
 (0)