使用R中的'calc'函数获取栅格像元坐标>>

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

我正在尝试在R中运行'calc'函数,但似乎无法找到一种方法来获取正在处理的单元格的坐标。我想做的很简单:在二进制栅格(0和1)上使用'calc'函数-如果栅格值为'0',则更改为'NA'。如果栅格值为'1',则应用一系列处理,我将需要针对这些处理将单元格坐标存储到变量中。

processAllCells = function(cell) {
  if (cell == 0) {
    cell = NA
    return(cell) 
  }
  else {
    cellCoords = coordinates(cell) ### This is what I'm trying to do. This does not work. See the error message.
    ### Here will go further processes using the cell coordinates.
    return(cell)
  }
}

outputRaster = calc(lake, processAllCells)

错误消息:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘coordinates’ for signature ‘"integer"’
In addition: Warning message:
In if (cell == 0) { :

 Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘coordinates’ for signature ‘"integer"’ 

谢谢大家!

我正在尝试在R中运行'calc'函数,但似乎无法找到一种方法来获取正在处理的单元格的坐标。我想做的很简单:在...

r coordinates raster r-raster calc
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.