我想剪辑一个光栅使用一个简单的功能集合的多边形,这样我就会有很多光栅剪辑,因为在我的sf收藏中有多边形。然后,我想把每个光栅剪辑保存为一个jpg。下面是一个可重复的例子:
library(sf)
library(raster)
austria1 <- getData('GADM', country='AUT', level=1)
austria1 <- st_as_sf(austria1)
climate <- getData('worldclim', var='bio', res=2.5)我想将气候剪辑成austria1中的九个多边形,所以我最终得到了9个光栅剪辑。然后,我想将这9个光栅剪辑作为jpg文件保存在我的工作目录中。
谢谢你的帮助!
标记
发布于 2020-05-26 21:59:07
示例数据
library(sf)
library(raster)
austria <- getData('GADM', country='AUT', level=1)
austria <- st_as_sf(austria)
climate <- getData('worldclim', var='bio', res=2.5)
climate <- climate[[1]] # just the first layerA循环
for (i in 1:nrow(austria)) {
a <- austria1[i, ]
fn <- tolower(paste0(a$NAME_1, ".jpg"))
print(fn); flush.console()
x <- crop(climate, a)
y <- mask(x, a)
jpeg(fn)
plot(y)
dev.off()
}您可能希望通过将一些默认参数更改为jpeg来改进jpg。
https://stackoverflow.com/questions/62030069
复制相似问题