select_time() with one time returns cubes without end-times, creating errors for st_as_stars() etc
cboettig opened this issue · 0 comments
cboettig commented
When we apply gdalcubes::select_time()
with a single time value, we get an object that does not have a start and end time. When we then use st_as_stars()
to convert this to a stars object, we get an erroneous end time. (Sometimes this is the origin time, 1970-01-01, which is bad, but sometimes I get non-date-times for this, which lead to breaking errors).
We can see this error using a simple modification to the example code for select_time()
# create image collection from example Landsat data only
# if not already done in other examples
if (!file.exists(file.path(tempdir(), "L8.db"))) {
L8_files <- list.files(system.file("L8NY18", package = "gdalcubes"),
".TIF", recursive = TRUE, full.names = TRUE)
create_image_collection(L8_files, "L8_L1TP", file.path(tempdir(), "L8.db"), quiet = TRUE)
}
L8.col = image_collection(file.path(tempdir(), "L8.db"))
v = cube_view(extent=list(left=388941.2, right=766552.4,
bottom=4345299, top=4744931, t0="2018-04", t1="2018-07"),
srs="EPSG:32618", nx = 497, ny=526, dt="P1M")
L8.cube = raster_cube(L8.col, v)
L8.rgb = select_bands(L8.cube, c("B02", "B03", "B04"))
Now select only one time:
L8.rgb = select_time(L8.rgb, c("2018-04"))
st_as_stars(L8.rgb)
gives us:
Note the erroneous end time (1970-01-01).