我已将光栅图像 (.tif) 上传到 R 中,它似乎加载正常,但我无法使用它的任何功能。库调用和下面发布的示例代码。
[在这里添加文本,因为没有它堆栈交换不允许我发帖,但我没有更多相关信息要添加]
library(sp)
library(ggplot2)
library(raster)
# image
site <- raster("C:/Users/ichth/OneDrive/Documents/Restoration_Implementation/Design_Project/Site_Raster.tif")
> site
class : RasterLayer
band : 1 (of 3 bands)
dimensions : 3597, 907, 3262479 (nrow, ncol, ncell)
resolution : 0.5, 0.5 (x, y)
extent : 958324.5, 958778, 761774.5, 763573 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=24.3333333333333 +lon_0=-81 +k=0.999941177 +x_0=200000.0001016 +y_0=0 +datum=NAD83 +units=us-ft +no_defs
source : Site_Raster.tif
names : Site_Raster_1
values : 3, 221 (min, max)
> total_area <- cellStats(site, sum)
Error in .local(x, ..., value) : unused argument (warn = FALSE)
> plot(site)
Error in .local(x, ..., value) : unused argument (warn = FALSE)
> hist(site)
Error in .local(x, ..., value) : unused argument (warn = FALSE)
> traceback()
13: `crs<-`(`*tmp*`, warn = FALSE, value = prj)
12: `crs<-`(`*tmp*`, warn = FALSE, value = prj)
11: .fromRasterLayerBrick(from)
10: asMethod(object)
9: methods::as(x, "SpatRaster")
8: rast(object)
7: rast(object)
6: .readRasterLayerValues(object, 1, object@nrows)
5: readAll(x)
4: readAll(x)
3: .local(x, stat, ...)
2: cellStats(site, sum)
1: cellStats(site, sum)
> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.4.2 raster_3.6-20 sp_1.5-1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 rstudioapi_0.14 magrittr_2.0.3 tidyselect_1.2.0 munsell_0.5.0
[6] colorspace_2.0-3 lattice_0.20-45 R6_2.5.1 rlang_1.1.0 fansi_1.0.3
[11] dplyr_1.0.10 tools_4.2.1 rgdal_1.6-2 grid_4.2.1 gtable_0.3.1
[16] utf8_1.2.2 terra_1.6-41 cli_3.4.1 withr_2.5.0 tibble_3.1.8
[21] lifecycle_1.0.3 vctrs_0.5.1 codetools_0.2-18 glue_1.6.2 compiler_4.2.1
[26] pillar_1.8.1 generics_0.1.3 scales_1.2.1 pkgconfig_2.0.3
>
从回溯中,错误来自
crs<-
函数。您的 pkg:terra
版本已过时。你应该更新它。我的版本是 terra_1.7-23,我无法重现错误。当前版本 terra
::crs<-
的帮助页面说“warn”是一个命名参数,默认为 FALSE
.