I am working with temperature data from PRISM. Thus far, I have been able to download data for individual days, then crop to shape files, and extract information accordingly. However, I am looking to combine multiple spatRaster files along the time dimension, so I end up with one data frame.
Thus far, I have tried two approaches. Firstly, I have tried combining my two days' worth of data into a single .rds file (stars object), then converting to spatRaster:
file1<- readRDS("file1.rds")
file2<- readRDS("file2.rds")
combinedfiles<- c(file1, file2, along = 3)
the combined file has the following description/attributes:
stars object with 3 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
PRISM_tmin_stable_4kmD2_202... -1.447 8.65 10.344 11.7053 16.168 20.97 60401
dimension(s):
from to offset delta refsys x/y
x 1 1405 -125 0.04167 NAD83 [x]
y 1 621 49.94 -0.04167 NAD83 [y]
new_dim 1 2 NA NA NA
however, I cannot seem to convert this to a spatRaster successfully:
temprast<-stack(combinedfiles)
Error in stack.default(combinedfiles) :
at least one vector element is required
I also tried converting each individual day to a spatRaster, then combining- this also did not work:
temprast<-rast(file1)
temprast2 <-rast(file2)
raster_brick <- brick(temprast, temprast2)
Error in .local(x, ...) :
unused argument (new("SpatRaster", pnt = new("Rcpp_SpatRaster", .xData = <environment>)))
The ultimate goal is to be able to crop this raster file to a shape file. It would be much easier if I combined the .rds files first in chronological order, before then dealing with shape file cropping etc. but if necessary, I guess my last option is to individually crop each .rds file to a shape file, extract data, and then combine (potentially using bind_rows)? But this seems very inefficient.
You are using
stack
where you intend to useraster::stack
You are usingraster::brick
where you should use a function from "terra", namelyc()
A sensible approach could be