我有一个全局栅格堆栈(三个栅格),其像素值是该像素的土地利用百分比。这是栅格元数据:
class : RasterBrick
dimensions : 3600, 7200, 25920000, 3 (nrow, ncol, ncell, nlayers)
resolution : 1, 1 (x, y)
extent : 0, 7200, 0, 3600 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : grass_baseline.tif
names : grass_2020, grass_2040, grass_2100
我尝试使用
area()
包中的 raster
函数,通过将像素值乘以栅格面积来计算每个像素的土地利用总面积。
当我这样做时,我收到以下错误:
Warning message:
In .couldBeLonLat(x, warnings = warnings) :
raster has a longitude/latitude CRS, but coordinates do not match that
这是区域栅格的元数据:
class : RasterLayer
dimensions : 3600, 7200, 25920000 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0, 7200, 0, 3600 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : memory
names : layer
values : -710.0924, 2211922 (min, max)
有人知道可能发生什么吗?
如果相关,我从几个 .nc 文件中组装了这个栅格堆栈,我使用
ncdf4
包将这些文件读入 R,并使用以下代码行将其转换为栅格:
raster(first_nc, xmn=0, xmx=7200, ymn=0, ymx=3600, crs=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs+ towgs84=0,0,0")
然后,我将其中几个栅格组合在一起作为堆栈,并使用
stars
包导出(以保留每个栅格的名称):
stack <- stack(first_nc,second_nc,third_nc)
names(stack) <- c('first_nc','second_nc','third_nc')
stars::write_stars(stars::st_as_stars(stack), "stack.tif")
然后我将 .tif 读入一个单独的脚本,这是我尝试计算面积的地方。
你有
#extent : 0, 7200, 0, 3600 (xmin, xmax, ymin, ymax)
#crs : +proj=longlat +datum=WGS84 +no_defs
即0到3600度之间的纬度。这是没有意义的,因为您不能超过北纬 90 度,因此无法计算这些像元的面积。并且指定的经度也不太可能是正确的,除非您的数据确实覆盖了地球 20 次。
我从一些 .nc 文件中组装了这个栅格堆栈,我用 ncdf4 包将这些文件读入 R 并转换为栅格
这不是一个好方法(除非所有其他方法都失败),并解释了奇怪的程度。你应该首先尝试的是
library(raster)
s <- stack(filenames)
或者更好地使用terra包(光栅的替换)
library(terra)
s <- rast(filenames)
这应该不是必需的,但如果您要自己设置范围,更合理的值将是 (-180, 180, -90, 90) 或 (0, 360, -90, 90)。