我正在尝试使用R中的'raster'包在Windows上读取.DEM格式的光栅文件。
在Windows 7中将数据加载到R中时,NA值出现问题,但在装有OSX Lion的Mac上却没有问题。在Windows上,似乎无法正确读取NA值。问题是为什么会这样?
使用以下R代码从USGS下载了使用的光栅文件:
download.file('http://edcftp.cr.usgs.gov/pub/data/gtopo30/global/e020n90.tar.gz', 'e020n90.tar.gz')
untar('e020n90.tar.gz')然后,我使用“ raster”包将栅格读入R。在OSX Lion和R64版本2.13.1中,可以识别NA值:
> onMac <- raster('E020N90.DEM')
> onMac
class       : RasterLayer 
dimensions  : 6000, 4800, 28800000  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 20, 60, 40, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
values      : /Users/Tam/Desktop/E020N90.DEM 
min value   : -9999 
max value   : 5483 
> summary(values(onMac))
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
-137       85      148      213      213     5483 13046160但是在Windows 7(64位,相同的R版本)上,它将将应为NA的单元格值转换为数字:
> onWindows <- raster('E020N90.DEM')
> onWindows
class       : RasterLayer 
dimensions  : 6000, 4800, 28800000  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 20, 60, 40, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0 
values      : E:/WorldDegreeDays/gsoddata/gtopo/E020N90.DEM 
min value   : -9999 
max value   : 5483 
> summary(values(onWindows))
Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1     150     946   27190   55540   65540在Windows上阅读时,为什么栅格中没有NA值?我该如何解决?我的猜测是它与数字的存储方式有关,许多NA值都转换为55540。
Windows中的信息(加载栅格后):
SessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] rgdal_0.7-1   raster_1.9-12 sp_0.9-88    
loaded via a namespace (and not attached):
[1] grid_2.13.1     lattice_0.19-30来自OSX的信息(加载栅格后):
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     
other attached packages:
[1] rgdal_0.6-33  raster_1.9-12 sp_0.9-88    
loaded via a namespace (and not attached):
[1] grid_2.13.1     lattice_0.19-33sessionInfo()在自己的帖子中加入吗?
                