重新投影时 CRS 参数出错

问题描述 投票:0回答:1

我正在尝试在 for 循环中迭代多个栅格(+500),但我遇到了一些问题。

首先我想将它们从 CRS EPSG:4326 重新投影到 CRS EPSG: 32614,然后使用具有较小分辨率和扩展名的掩模栅格对它们重新采样,最后为工作目录中的每个栅格写入结果栅格,但是我收到了有关 CRS 参数的以下错误消息:

Error in CRS(x) : PROJ4 argument-value pairs must begin with +: E:\Proyecto PM2.5\2_PM_2.5_Processing\Test/AOD_MOD_CDTDB_April_2016.tif

我在这里看了很多帖子,但我无法解决这个问题。下面是我的代码,如果这位 R 初学者能提供任何帮助,我将不胜感激

#find all tifs in your directory
dir<-"E:\\Proyecto PM2.5\\2_PM_2.5_Processing\\Test"

#get a list of all files with .tif in the name in the directory
files<-list.files(path=dir, pattern='.tif', full.names = TRUE)

#raster with the expected characteristics: extension, cellsize, number of pixels
r_ref <- raster("E:\\Proyecto PM2.5\\3_PM_2.5_Entrega\\temporal\\Raster_C.tif")

for (file in files){
  name <- file
  projectRaster(name,crs="+init=epsg:32614")
  resample(file,r_ref,method="ngb")
  savename<-sub("ZMVM",name,basename(file))
  writeRaster(r,file=savename,)
}
r r-raster rgdal
1个回答
1
投票

你愿意

for (file in files){
   name <- file
   projectRaster(name,crs="+init=epsg:32614")

所以

name
file
相同(为什么要复制?)---文件名。 您要求
projectRaster
投影字符串(文件名)。你的意图肯定是这样的

for (file in files){
   r <- raster(file)
   projectRaster(r, crs="+init=epsg:32614")
© www.soinside.com 2019 - 2024. All rights reserved.