У меня есть большое количество растров (файлов ASCII), которые я хочу: 1. Перепроектировать из равной области Ламбертса в WGS 84 2. Обрезать получившиеся растры WGS 84 до степени 3. Записать получившиеся растры в каталог
Я знаю, что наложение растров и перепроецирование приведут к проблемам с памятью. Поэтому я попытался для l oop, который проходит через каждый растр, перепроектирует кадрирование и сохраняет его в выходной каталог. Даже тогда у меня проблемы с памятью. Код работает довольно быстро, если я просто обрезаю и маскирую растры, все становится проблематичным c, когда я хочу перепроектировать. вот мой код
library(raster)
library(doParallel)
library(rgdal)
#Define how many cores you want to use
UseCores <- detectCores()-1
#Register CoreCluster
cl <- makeCluster (UseCores)
registerDoParallel (cl)
# Start the clock!
ptm <- proc.time ()
# Reading the shapefile (mask to crop later)
Maskshp <- readOGR("G:/PhD BOKU/DATA/GIS Data/austria","AUT0")
# Name the output path and creat a directory to store the final results
outpath <- "C:/Users/chakraborty/Desktop/cropdata/"
dir.create(outpath)
# Reading the raster to crop
setwd("C:/Users/chakraborty/Desktop/MPI_rcp85_2080s_Bioclimatic")
files <- list.files(pattern=".tif")
# add the output directory
outfiles <- paste0(outpath, files)
for(i in 1:length(files)) {
r <-raster(files[i])
projection(r)<- CRS("+proj=aea +lat_1=43 +lat_2=62 +lat_0=30 +lon_0=15 +x_0=0 +y_0=0 +ellps=intl
+units=m +no_defs")
newproj <- CRS("+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs")
rWGS <- projectRaster(r, crs= newproj,res= 0.008333334)
rc <- crop(rWGS, Maskshp)
rc1 <- mask(rc,Maskshp)
rc1 <- writeRaster(rc1, outfiles[i],format="GTiff")
}
#end cluster
stopCluster (cl)
# Stop the clock
proc.time() -ptm
# Takes 102 seconds to crop and write 20 rasters from Europe to Austrian Extent