r中的extactExtractr,错误:[名称< - ]名称的数量不正确

发布于 2025-02-10 04:15:51 字数 526 浏览 3 评论 0原文

使用 eckectextractr package(cran link) 它一直在起作用:我有一个耙子堆栈(s)并用这样的形状文件(Inv)剪切,

df1 <- exact_extract(s, INV, fun = c("mean", "min", "max", "median", "variance"), append_cols = c("FLIK"))

但是从今天开始,我就会有一个错误消息

错误:[名称&lt; - ]名称的数量不正确

当我列出名称名称>名称>或名称>名称(Inv)的名称时,名称的数量不正确。我看不到任何错误。

我看不到任何隐藏的名字吗?有名字的障碍吗?

Used exactextractr package (CRAN link) already and it always worked : I have a raster stack (s) and cut out with a shape-file (INV) like this

df1 <- exact_extract(s, INV, fun = c("mean", "min", "max", "median", "variance"), append_cols = c("FLIK"))

But as from today I have an error message constantly like

Error: [names<-] incorrect number of names

When I list names either of names(s) or names(INV) I cannot see any mistake.

Are there any hidden names I cannot see ? Is there alimit of names ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趴在窗边数星星i 2025-02-17 04:15:51

我今天遇到了同样的问题,我设法以简单的方式修复了我的代码。当我读取栅格文件(.nc)时,我从raster库中使用了stack函数。此代码Ruturn是一个栅格扇形对象。下面的代码给了我与您提到的相同的错误。

library(raster)
library(sf)
library(exactextractr)

# Reading shapefile data
shapefile<- sf::st_read("PATH_TO_SHAPEFILE")

# Reading raster data
raster <- raster::stack("PATH_TO_RASTER")

# Using exact_extract function from exactextractr package
df <- exact_extract(raster , shapefile, 'mean')

我设法通过使用brick函数(从同一库中)返回rasterbrick来解决此问题。这样,我可以在没有错误的情况下运行代码,如下所示:

library(raster)
library(sf)
library(exactextractr)

# Reading shapefile data
shapefile<- sf::st_read("PATH_TO_SHAPEFILE")

# Reading raster data
raster <- raster::brick("PATH_TO_RASTER")

# Using exact_extract function from exactextractr package
df <- exact_extract(raster , shapefile, 'mean')

我不完全知道这里发生了什么,因为我过去曾经使用stack函数,这根本没有问题。由于某种原因,使用Brick这次修复了我的代码。我希望这可以帮助您。

I had the same problem today and I manage to fix my code in a simple way. When I read the raster file (.nc), I used the stack function from raster library. This code ruturns a RasterStack object. The code below gave me the same error as you mentioned.

library(raster)
library(sf)
library(exactextractr)

# Reading shapefile data
shapefile<- sf::st_read("PATH_TO_SHAPEFILE")

# Reading raster data
raster <- raster::stack("PATH_TO_RASTER")

# Using exact_extract function from exactextractr package
df <- exact_extract(raster , shapefile, 'mean')

I managed to fix that by using the brick function, from the same library, that returns a RasterBrick. That way, I could run my code without errors, as following:

library(raster)
library(sf)
library(exactextractr)

# Reading shapefile data
shapefile<- sf::st_read("PATH_TO_SHAPEFILE")

# Reading raster data
raster <- raster::brick("PATH_TO_RASTER")

# Using exact_extract function from exactextractr package
df <- exact_extract(raster , shapefile, 'mean')

I don't exactly knows what is happening here, because I have used the stack function in the past with no problem at all. For some reason, using brick fixed my code this time. I hope this can help you.

°如果伤别离去 2025-02-17 04:15:51

事实是,TIFF中有多个层/频道。首先,您必须将其减少到一层,然后给出正确的名称数。

It was about the fact, that there are more than one layers/channels in a tiff. First you have to reduce to one layer, then it gives the correct number of names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文