2013-05-29 134 views
9

我正在讀取R中的.tif文件並獲取下面列出的4條警告消息。當我按照第4條消息的指示時,前3個警告仍然保留,但從文件中讀取的值在每個像素處劇烈變化。請幫助我從.tif文件正確讀取數據。示例文件可以在鏈接上找到:ftp://ftp.ntsg.umt.edu/pub/MODIS/NTSG_Products/MOD16/MOD16A2_MONTHLY.MERRA_GMAO_1kmALB/GEOTIFF_0.05degree/讀取R中的.tif文件

我的代碼:

remove(list=ls()) 

library(tiff) 

library(raster) 

str_name<-'MOD16A2_ET_0.05deg_GEO_2008M01.tif' 

read_file<-readTIFF(str_name) 

警告信息:

1: In readTIFF(str_name) : 
    TIFFReadDirectory: Unknown field with tag 33550 (0x830e) encountered 
2: In readTIFF(str_name) : 
    TIFFReadDirectory: Unknown field with tag 33922 (0x8482) encountered 
3: In readTIFF(str_name) : 
    TIFFReadDirectory: Unknown field with tag 34735 (0x87af) encountered 
4: In readTIFF(str_name) : 
    tiff package currently only supports unsigned integer or float sample formats in direct mode, but the image contains signed integer format - it will be treated as unsigned (use native=TRUE or convert=TRUE to avoid this issue) 

請幫我正確讀取TIF文件這個問題。提前致謝。

回答

8

你是否嘗試簡單的光柵包光柵函數(或堆棧如果多個分層tif)?光柵包是爲了處理與地理參考柵格數據集:

library(raster) 
str_name<-'MOD16A2_ET_0.05deg_GEO_2008M01.tif' 
imported_raster=raster(str_name) 

的簡單代碼上述工程,併產生具有以下性質的光柵對象:

class  : RasterLayer 
dimensions : 2800, 7200, 20160000 (nrow, ncol, ncell) 
resolution : 0.05, 0.05 (x, y) 
extent  : -180, 180, -60, 80 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:\Users\lfortini\Downloads\MOD16A2_ET_0.05deg_GEO_2000M01.tif 
names  : MOD16A2_ET_0.05deg_GEO_2000M01 
values  : -32768, 32767 (min, max) 
+1

嗨,我使用了命令,但得到以下錯誤消息:錯誤.rasterObjectFromFile(x,band = band,objecttype =「RasterLayer」,: 無法從此文件創建RasterLayer對象;也許您需要首先安裝rgdal – Munish

+0

我的R版本是:2.15.2,如果這有助於解決問題,當我加載光柵包時,它給了我警告消息:加載所需包:sp 警告消息: 1:包'光柵'是在R 2.15.3 2:package'sp'是在R 2.15.3版本下構建的 – Munish

+0

也許你需要先安裝rgdal – mdsumner

4

只需讀取的像素作爲無符號和將它們轉換爲簽署:

t = readTIFF("MOD16A2_ET_0.05deg_GEO_2008M01.tif", as.is=TRUE) 
t[t >= 32738L] = -65536L + t[t >= 32738L] 

在圖像看,你可能還需要-32768轉換爲NA因爲這似乎是在文件中使用:

t[t == -32768L] = NA 

如果你想的整數[-1,1]實數現在轉換,只是做

t = t/32768 

前三警告只是告訴你,有在文件中附加的自定義標籤。

+0

嗨西蒙,你的方法似乎通過前兩行正確讀取值;唯一的問題是這些值比使用光柵功能讀取tif文件並將其轉換爲矩陣的其他方法多1。例如,如果另一種方法在[650,1200]處顯示值199,則您的方法會給出200;否則看起來是正確的。謝謝。 – Munish