1. 程式人生 > >菜鳥速成記-IDL讀取顯示dat檔案

菜鳥速成記-IDL讀取顯示dat檔案

DAT檔案的讀取

問題描述

之前,博主沒有理解dat檔案導致對檔案獲取產生問題和誤解,還可笑的認為沒辦法獲取demission的話,是沒有辦法讀取dat檔案的。

由於dat檔案是遙感影像的常用格式之一。所以,首先認識一番,dat檔案。

  1. 先找個資料夾看看它在哪
    Markdown

2.看看它們到底長什麼樣子

  • hdr 標頭檔案
    Markdown

  • dat 檔案
    Markdown

3.思考怎麼去讀取dat檔案

讀取dat檔案的思路:
- 首先獲取到dat檔案的標頭檔案資訊。

  • 呼叫函式進行顯示READ_BINARY()

Markdown

程式碼實現過程

由於程式碼實現過於簡單,所以沒有寫相應的註釋,有什麼不會的直接留言~

pro read_dat

hdr_path=DIALOG_PICKFILE(/READ)
hdr_path=string(hdr_path)

head_info=strarr(6)
openr,lun,hdr_path,/get_lun
readf,lun,head_info
;print,head_info
free_lun,lun
 I=5;
 while (i gt 0) do begin
   temp=string(head_info[i])
   IF(temp.contains('samples'))THEN BEGIN
     xs=temp
   ENDIF
   IF
(temp.contains('bands'))THEN BEGIN band=temp ENDIF IF(temp.contains('lines'))THEN BEGIN ys=temp ENDIF IF i GT 5 THEN BEGIN BREAK ENDIF i-- endwhile ;print,head_info[j] ;xs=string(head_info[3]) xs=xs.split("=") xs=xs[1] ;ys=string(head_info[4]) ys=ys.split("=") ys=ys[1
] ;band=string(head_info[4]) band=band.split("=") band=band[1] img_path=dialog_pickfile(/read) img_path=string(img_path) imageSize=[uint(xs),uint(ys)] mbells = READ_BINARY(img_path, DATA_DIMS = imagesize) ; TrueColor display DEVICE, DECOMPOSED = 0 LOADCT, 0 WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'A Binary Image, Scaled' TVSCL, mbells end

程式碼實現的效果

Markdown

灰度圖實現效果

Markdown

送你們個驚喜

在GIS的沙場,傳播有價值的東西!