1

I would like to stack a raster dataset taking into account the number of days between images. Sometimes the number of dates between observations are 8, 16 or 365 days.

Is there any function to do it automatically?

The code that I have right now is as follows:

setwd("C:\\NDVI_prueba")
rlist=list.files(pattern=".tif$", full.names=T)
rasters=stack(rlist)
rasters

I guess that this code does not count the separation between days and has the same interval for all the images?

The name of the files is NDVI.2000_01_01_NDVI.

Is it correct or should I give a special name to be able to determine the date in each image?

0
4

Create a stack:

> mystack = stack(lapply(1:5, function(...){raster(matrix(runif(24),3,8))}))

Set Z to some arbitrary values:

> mystack = setZ(mystack,c(1,23,44,55,901))

Get them back:

> getZ(mystack)
[1]   1  23  44  55 901

If you want the Zs to be dates, make them dates:

> mystack = setZ(mystack,as.Date(paste0("2001-01-0",1:5)))
> getZ(mystack)
[1] "2001-01-01" "2001-01-02" "2001-01-03" "2001-01-04" "2001-01-05"

Pulling the dates out of your filenames (if that's what you need to do) is not GIS-related so if you struggle with that ask on www.stackoverflow.com

Most functions that work on stacks will not take into account your Z values though - if you need to do some analysis that depends on layer 1 being 23 days after layer 2 and layer 2 being 76 days after layer 3 then you have to pull out the Z values yourself to work with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.