Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 在R中重新投影光栅列表_Performance_Raster_Reprojection Error - Fatal编程技术网

Performance 在R中重新投影光栅列表

Performance 在R中重新投影光栅列表,performance,raster,reprojection-error,Performance,Raster,Reprojection Error,我有大量的光栅(ASCII文件),我想: 1.从Lamberts等面积重新投影至WGS 84 2.在一定程度上裁剪生成的WGS 84光栅 3.将结果光栅写入目录 我知道堆叠光栅和重新投影会遇到内存问题。因此,我尝试了一个for循环,该循环遍历每个光栅,重新投影作物并将其保存到输出目录。 即使这样,我也会遇到内存问题。如果我只是裁剪和遮罩光栅,代码运行得相当快,当我想重新投影时,事情就会出现问题。 这是我的密码 library(raster) library(doParallel) library

我有大量的光栅(ASCII文件),我想: 1.从Lamberts等面积重新投影至WGS 84 2.在一定程度上裁剪生成的WGS 84光栅 3.将结果光栅写入目录

我知道堆叠光栅和重新投影会遇到内存问题。因此,我尝试了一个for循环,该循环遍历每个光栅,重新投影作物并将其保存到输出目录。 即使这样,我也会遇到内存问题。如果我只是裁剪和遮罩光栅,代码运行得相当快,当我想重新投影时,事情就会出现问题。 这是我的密码

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
库(光栅)
图书馆(双平行)
图书馆(rgdal)
#定义要使用的核心数
使用核心