为什么 terra::cellSize() 和 raster::area() 会产生不同的栅格像元面积估计值?

Why do terra::cellSize() and raster::area() produce different estimates of raster cell area?

我刚刚注意到 terra::cellSize() 生成的像元面积估计值与 raster::area() 生成的不匹配。

首先,为什么这两种方法提供的答案不同?第二,哪个估计最准确?请参阅下面的示例。

library(raster)
#> Loading required package: sp
library(terra)
#> terra version 1.3.4

# make test raster with raster::raster()
a <- raster::raster(ncols = 100, nrows = 100,
            xmn = -84, xmx = -83, 
            ymn = 42, ymx = 43)

# make test raster with terra::rast()
b <- terra::rast(ncols = 100, nrows = 100, 
          xmin = -84, xmax = -83, 
          ymin = 42, ymax = 43)

# calculate cell areas (km2)
a_area <- raster::area(a) # km by default
b_area <- terra::cellSize(b, unit = "km")

# sum across cells
a_sum <- raster::cellStats(a_area, "sum")
b_sum <- terra::global(b_area, fun = "sum")

a_sum
#> [1] 9088.98
b_sum
#>           sum
#> area 9130.795

# note that this terra workflow yields the same answer as terra::expanse()
terra::expanse(b, unit = "km")
#> [1] 9130.795


sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS  10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] terra_1.3-4  raster_3.4-5 sp_1.4-5    
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.6        codetools_0.2-18  lattice_0.20-41   digest_0.6.27    
#>  [5] grid_4.0.2        magrittr_2.0.1    evaluate_0.14     highr_0.8        
#>  [9] rlang_0.4.10      stringi_1.5.3     rmarkdown_2.6     rgdal_1.5-19     
#> [13] tools_4.0.2       stringr_1.4.0     xfun_0.20         yaml_2.2.1       
#> [17] compiler_4.0.2    htmltools_0.5.1.1 knitr_1.31
packageVersion("raster")
#> [1] '3.4.5'
packageVersion("terra")
#> [1] '1.3.4'

reprex package (v0.3.0)

于 2021-07-08 创建

过去几年我一直在使用 raster(并且很喜欢它),最近被更新的 terra 软件包提供的速度和其他改进所震撼。我假设 terra::cellSize()(或 terra::expanse(),就此而言)提供的面积估计比​​ raster::area() 更准确,但我想在更新之前了解更多关于更改的内容先前的面积估计。

感谢你所做的一切,https://github.com/rspatial

raster 使用单元格的宽度(经度)和高度(纬度)的乘积。 terra 更精确,它计算单元格的球形面积(由其四个角定义)。这在高纬度地区最重要,那里的像元宽度变化最大,并且像元底部和顶部之间可能不同。因此,在高纬度和垂直分辨率较低的像元中,差异最大。

此处图示:

library(raster)
library(terra)
a <- raster::raster()
b <- terra::rast()
values(a) <- 1:ncell(a)
values(b) <- 1:ncell(b)

a_rast <- rast(area(a))
a_terra <- cellSize(b, unit = "km")

dif <- a_terra - a_rast    
reldif <- 100 * dif / a_terra
plot(reldif)

在两极附近,这些像元的差异几乎为 1%,而在赤道为 ~0。

一个相关的主要变化是 terra 还计算投影(即不是经纬度)栅格的真实像元大小;而不是假设标称分辨率是恒定的。

r <- rast(ncols=90, nrows=45, ymin=-80, ymax=80)
m <- project(r, "+proj=merc")

bad <- init(m, prod(res(m)) / 1000000, names="naive")
good <- cellSize(m, unit="km", names="corrected")
plot(c(good, bad), nc=1, mar=c(2,2,1,6))