首页 > 解决方案 > 为什么在 r 中重新采样栅格时会得到 NA 值

问题描述

我有两个不同程度的栅格,但是当我在 R 中使用 resample 时,输出是一个空白栅格......我该如何解决这个问题?请参阅下面使用的一些代码....重新采样的栅格出现在值中带有 NA....

show(alt)

class       : RasterLayer 
dimensions  : 1800, 4320, 7776000  (nrow, ncol, ncell)
resolution  : 0.08333334, 0.08333334  (x, y)
extent      : -180, 180, -60, 90.00001  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : C:\Users\Mafalda\Documents\bio_5m_esri\alt5.asc 
names       : alt5 
values      : -2147483648, 2147483647  (min, max)

show(hfp)

class       : RasterLayer 
dimensions  : 16382, 36081, 591078942  (nrow, ncol, ncell)
resolution  : 1000, 1000  (x, y)
extent      : -18040094, 18040906, -7363043, 9018957  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : C:\Users\Mafalda\Desktop\Iva\HumanFootprintv2\hfp2009.asc 
names       : hfp2009 
values      : -2147483648, 2147483647  (min, max)

hfpResamp <- resample(hfp, alt, resample='bilinear')

show(hfpResamp)

class       : RasterLayer 
dimensions  : 1800, 4320, 7776000  (nrow, ncol, ncell)
resolution  : 0.08333334, 0.08333334  (x, y)
extent      : -180, 180, -60, 90.00001  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : in memory
names       : hfp2009 
values      : NA, NA  (min, max)

extent(hfp)
class       : Extent 
xmin        : -18040094 
xmax        : 18040906 
ymin        : -7363043 
ymax        : 9018957 


extent(alt)

class       : Extent 
xmin        : -180 
xmax        : 180 
ymin        : -60 
ymax        : 90.00001 

标签: rraster

解决方案


reproject您需要先保存hfp文件:

hfp_re <- projectRaster(hfp, alt)
# now you can resample:
hfpResamp <- resample(hfp_re, alt, resample='bilinear')

推荐阅读