【问题标题】:Error with CRS argument while reprojecting重新投影时 CRS 参数出错
【发布时间】:2021-02-12 15:39:29
【问题描述】:

我正在尝试在 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-raster rgdal


    【解决方案1】:

    你会的

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

    所以namefile 相同(为什么要复制?)--- 文件名。 您要求projectRaster 投影一个字符串(文件名)。你想要的肯定是这样的

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

    【讨论】:

      猜你喜欢
      • 2019-08-09
      • 2021-05-15
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      相关资源
      最近更新 更多