当栅格数量可变时,在特定位置连接多个栅格
Join multiple rasters at specific locations, when the number of rasters is variable
给定 "n" 个栅格,每个栅格正好 100x100 像素,我想将它们全部组合在一个图中,这样每行正好有 4 张图像。对于 n > 4,应创建一个新行,依此类推。因此,创建的空图的尺寸将沿 x 轴固定,但 y 轴将取决于栅格的数量。我使用 "magick" 包中的 image_montage() 函数来生成蒙太奇,如下所示:
mag_montage <- list()
for(ii in 1:n){
filelist_crop <- list.files()[grep(".png",list.files())]
mag_montagetemp <- image_read(filelist_crop)
mag_montage[[ii]] <- image_montage(mag_montagetemp)
}
但我无法通过这种方式控制文件蒙太奇中每个单独文件的具体位置。了解位置非常重要,因为我需要从组合栅格中选择特定的 xy 坐标(使用 "locator")进行一些下游处理。任何帮助都感激不尽。谢谢。
通过这种方式,您可以将列表 rlist
中的所有栅格绘制到一个包含 4 列的图中:
library(raster)
n <- 26
rlist <- lapply(1:n,function(x) raster(system.file("external/test.grd", package="raster")))
par(mfrow=c(ceiling(n/4),4))
for (ii in 1:length(rlist)){
plot(rlist[[ii]])
## additional options for plot to omit legend and box
#bty="n", box=FALSE, axes=F, legend=F
}
给定 "n" 个栅格,每个栅格正好 100x100 像素,我想将它们全部组合在一个图中,这样每行正好有 4 张图像。对于 n > 4,应创建一个新行,依此类推。因此,创建的空图的尺寸将沿 x 轴固定,但 y 轴将取决于栅格的数量。我使用 "magick" 包中的 image_montage() 函数来生成蒙太奇,如下所示:
mag_montage <- list()
for(ii in 1:n){
filelist_crop <- list.files()[grep(".png",list.files())]
mag_montagetemp <- image_read(filelist_crop)
mag_montage[[ii]] <- image_montage(mag_montagetemp)
}
但我无法通过这种方式控制文件蒙太奇中每个单独文件的具体位置。了解位置非常重要,因为我需要从组合栅格中选择特定的 xy 坐标(使用 "locator")进行一些下游处理。任何帮助都感激不尽。谢谢。
通过这种方式,您可以将列表 rlist
中的所有栅格绘制到一个包含 4 列的图中:
library(raster)
n <- 26
rlist <- lapply(1:n,function(x) raster(system.file("external/test.grd", package="raster")))
par(mfrow=c(ceiling(n/4),4))
for (ii in 1:length(rlist)){
plot(rlist[[ii]])
## additional options for plot to omit legend and box
#bty="n", box=FALSE, axes=F, legend=F
}