Skip to content

Commit 4292774

Browse files
committed
time support; #484
1 parent b2c8e93 commit 4292774

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

R/raster.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ st_as_stars.SpatRaster = function(.x, ..., ignore_file = FALSE) {
146146
stop(paste("error reading", file, "bands", paste0(RasterIO$bands, collapse = " ")))
147147
lst[[i]] = r
148148
}
149-
if (length(lst) > 1)
150-
merge(setNames(do.call(c, lst), names(.x)))
151-
else
152-
r
149+
ret = if (length(lst) > 1)
150+
merge(setNames(do.call(c, lst), names(.x)))
151+
else
152+
r
153+
if (!all(is.na(time(.x))))
154+
ret = st_set_dimensions(ret, 3, values = time(.x), names = "time")
155+
ret
153156
}
154157

155158
v = terra::values(.x, mat = FALSE)
@@ -177,8 +180,11 @@ st_as_stars.SpatRaster = function(.x, ..., ignore_file = FALSE) {
177180
ret = st_as_stars(l, dimensions = create_dimensions(dimensions, get_raster()))
178181
if (dim(ret)[3] == 1)
179182
adrop(ret, 3)
180-
else
183+
else {
184+
if (!all(is.na(time(.x))))
185+
ret = st_set_dimensions(ret, 3, values = time(.x), names = "time")
181186
ret
187+
}
182188
}
183189

184190
#' Coerce stars object into a terra SpatRaster

0 commit comments

Comments
 (0)