I have a simple csv file with lon/lat/time/values columns:
df <- data.frame(longitude=rep(c(10.5,11,12),10),
latitude=rep(c(10.5,11,12),10),
date= as.Date(rep(c("2012-01-01", "2012-02-01", "2012-03-01"), 10)),
vals=rnorm(30,10,5))
I'd like to convert this to a SpatRaster using the S4 method for signature 'data.frame'
rast(x, type="xyz", crs="", digits=6, extent=NULL), where each "date" would be a seperate layer.
Importing without the date works fine:
df.subset <- select(df,-date)
tmp <- terra::rast(df.subset, type="xyz")
I've tried to split the SpatRaster by date but get a Error in .local(x, f, ...) : length(f) == nlyr(x) is not TRUE error:
split(tmp, as.factor(df$date))
I can think of an approach using a loop that
splits the df by date:
split(df, c("2012-01-01", "2012-02-01", "2012-03-01"))creates seperate SpatRasters for each individual date
Use
mergeto combine individual SpatRasters with named layers
Is there a tidier way of doing this in terra?
