@@ -105,6 +105,9 @@ sits_merge.sar_cube <- function(data1, data2, ...) {
105
105
dplyr :: filter(data2 , .data [[" tile" ]] %in% common_tiles ),
106
106
.data [[" tile" ]]
107
107
)
108
+ if (length(.cube_timeline(data2 )[[1 ]]) == 1 ){
109
+ return (.merge_single_timeline(data1 , data2 ))
110
+ }
108
111
if (inherits(data2 , " sar_cube" )) {
109
112
return (.merge_equal_cube(data1 , data2 ))
110
113
} else {
@@ -131,10 +134,9 @@ sits_merge.raster_cube <- function(data1, data2, ...) {
131
134
dplyr :: filter(data2 , .data [[" tile" ]] %in% common_tiles ),
132
135
.data [[" tile" ]]
133
136
)
134
- if (length(.cube_timeline(data2 )) == 1 ){
137
+ if (length(.cube_timeline(data2 )[[ 1 ]] ) == 1 ){
135
138
return (.merge_single_timeline(data1 , data2 ))
136
139
}
137
-
138
140
if (inherits(data2 , " sar_cube" )) {
139
141
return (.merge_distinct_cube(data1 , data2 ))
140
142
} else {
@@ -200,17 +202,23 @@ sits_merge.raster_cube <- function(data1, data2, ...) {
200
202
# Return cubes merged
201
203
return (data1 )
202
204
}
205
+
203
206
.merge_single_timeline <- function (data1 , data2 ){
204
- # Get data1 timeline
207
+ # Get data1 timeline.
205
208
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
+ # Create new `file_info` using dates from `data1` timeline.
210
+ fi_new <- purrr :: map(seq_len(nrow(data2 )), function (row ) {
211
+ data_row <- data2 [row ,]
212
+
213
+ fi <- .fi(data_row )
214
+ fi [[" date" ]] <- as.Date(d1_tl [1 : nrow(data_row )])
215
+
209
216
return (fi )
210
217
})
218
+ # Assign the new `file_into` into `data2`
211
219
data2 [[" file_info" ]] <- fi_new
212
- data1 <- .cube_merge( data1 , data2 )
213
- return (data1 )
220
+ # Merge cubes and return
221
+ .cube_merge (data1 , data2 )
214
222
}
215
223
216
224
# ' @rdname sits_merge
0 commit comments