我使用splitRaster
库中的函数SpaDES
创建了栅格图块:
set.seed(123)
# Create a matrix with random data
xy <- matrix(rnorm(400),20,20)
# Turn the matrix into a raster
rast <- raster(xy)
# Give it lat/lon coords for 39-42°E, 12-10°S
extent(rast) <- c(39,42,-12,-10)
# assign a projection
projection(rast) <- CRS("+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs")
# split it into 4 tiles and add an overlap (buffer) of one cell in x and one in y-direction
library(SpaDES)
split_rast <- splitRaster(r = rast, nx = 2, ny = 2, buffer = c(1,1))
# save the tile in tif format "GTiff"
tile_name <- c("1", "2", "3", "4")
for (i in 1:length(tile_name)) {
writeRaster(split_dhm[[i]], filename = paste0("path\\tile",tile_name[i],".tif"),
format = "GTiff")
}
实际上,我的栅格不是矩形的,大小超过3 GB。
将单个文件(仍然很大)保存为tif之后,我使用RSAGA
处理了它们以计算例如曲率:
for (i in 1:length(tile_name)) {
rsaga.slope.asp.curv(in.dem = paste0("path\\tile", tile_name[i], ".tif"),
out.cgene = paste0("path\\general_curvature_tile",
tile_name[i]),
env = work_env)
}
然后我使用raster
重新加载了它:
path_name <- c("path\\tile1.sdat", "path\\tile2.sdat", "path\\tile3.sdat", "path\\tile4.sdat")
rasterlayer <- list()
for (i in 1:length(path_name)) {
rasterlayer[[i]] <- raster(paste0(path_name[i]))
}
如何删除每个图块中的重叠部分?