0

我正在创建 ASCII 文件以包含在R.

当我创建图层并查看栅格值时,我可以看到它们并且它们是正确的,例如:

> r_test3
class      : RasterLayer 
dimensions : 4698, 3919, 18411462  (nrow, ncol, ncell)
resolution : 50, 50  (x, y)
extent     : 159500, 355450, 160454.6, 395354.6  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601272 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 
source     : memory
names      : layer 
values     : 1, 43385  (min, max)

然后当我堆叠三个栅格时,一切似乎都是正确的:

RegionalGridsBest
class      : RasterStack 
dimensions : 4698, 3919, 18411462, 3  (nrow, ncol, ncell, nlayers)
resolution : 50, 50  (x, y)
extent     : 159500, 355450, 160454.6, 395354.6  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601272 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 
names      : layer.1, layer.2, layer.3 
min values :       1,       1,       1 
max values :   43385,   92917,   95704 

但是,当我getValues为栅格时,他们只显示 NA:

> getValues(RegionalGridsBest)
            layer.1 layer.2 layer.3
       [1,]      NA      NA      NA
       [2,]      NA      NA      NA
       [3,]      NA      NA      NA
       [4,]      NA      NA      NA
       [5,]      NA      NA      NA
       [6,]      NA      NA      NA
       [7,]      NA      NA      NA
       [8,]      NA      NA      NA
       [9,]      NA      NA      NA
      [10,]      NA      NA      NA
      [11,]      NA      NA      NA
      [12,]      NA      NA      NA
      [13,]      NA      NA      NA

然后由于这个原因,当我尝试使用该vifstep功能时出现此错误:

vifstep(RegionalGridsBest, th = 3, maxobservations = 10000) 

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

我不知道如何解决这个问题或我做错了什么。

编辑

NA 值在文件中,尽管在创建层时设置为 0 值:

> summary(RegionalGridsBest)
Error in apply(object@data@values, 2, quantile, na.rm = TRUE) : 
  no slot of name "data" for this object of class "RasterStack"

> summary(r_test3)
             layer
Min.           1.0
1st Qu.    18407.0
Median     28176.5
3rd Qu.    41293.0
Max.       43385.0
NA's    17850028.0

> summary(r_test2)
           layer
Min.           1
1st Qu.    40505
Median     58967
3rd Qu.    75139
Max.       92917
NA's    17086764

> summary(r_test)
           layer
Min.           1
1st Qu.    25570
Median     51215
3rd Qu.    66486
Max.       95704
NA's    17980349
4

1 回答 1

0

您所展示的是前 13 个单元格是 NA --- 这很常见。我怀疑你的一层只有 NA。你能检查/显示

summary(RegionalGridsBest)

这显然与NA价值观有关。从例子

library(usdm)
file <- system.file("external/spain.grd", package="usdm")
r <- stack(file)
v <- vifstep(r, th=10)

如果一层都是 NA 则失败

r[[1]][] <- NA
v <- vifstep(r, th=10)
#Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
#  0 (non-NA) cases

但也有没有 NA 的单元格

r <- stack(file)
r[[1]][1:500] <- NA
r[[2]][450:870] <- NA
v <- vifstep(r, th=10)
#Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
#  0 (non-NA) cases

你可以检查一下

 tst <- any(is.na(RegionalGridsBest))

单元格不应全部为 1 (TRUE),应该有一些单元格为 0 (FALSE) 才能使 vifstep 工作。

于 2020-12-04T20:49:46.530 回答