我刚刚注意到,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 包(v0.3.0)于 2021-07-08 创建
raster
在过去的几年里,我一直在使用(并且喜欢它),最近被新terra
软件包提供的速度和其他改进所震撼。我假设terra::cellSize()
(或terra::expanse()
,就此而言)提供的面积估计值比 更准确raster::area()
,但我很想在更新之前的面积估计值之前了解更多有关变化的信息。
感谢您所做的一切,https://github.com/rspatial!