Now, let's say I want to crop the stacked images by a given geographic extent. Here's the referring code.
## file import library(raster) ch_fls_chirps <- list.files("path/to/tif", pattern = ".tif$", full.names = TRUE) rst_chirps <- stack(ch_fls_chirps) ## desired extent (xmin, xmax, ymin, ymax) ext <- extent(c(37, 37.7, -3.4, -2.84)) ## cropping (with output storage) rst_chirps <- crop(rst_chirps, ext, snap = "out", filename = "path/to/tif/CRP", bylayer = TRUE, suffix = names(rst_chirps), format = "GTiff", overwrite = TRUE)
raster::crop, the following error message is thrown:
Error in checkAtAssignment("RasterStack", "legend", ".RasterLegend") : ‘legend’ is not a slot in class “RasterStack”
By contrast, the code works just fine when output storage is omitted during
raster::crop and manually done afterwards.
## cropping (without output storage) rst_chirps <- crop(rst_chirps, ext, snap = "out") rst_chirps <- writeRaster(rst_chirps, filename = "path/to/tif/CRP"), bylayer = TRUE, suffix = names(rst_chirps), format = "GTiff", overwrite = TRUE)
Can anybody tell me what the issue with direct output storage from within the
crop command is all about?