您的位置:首页 > 其它

菜鸟速成记-IDL读取显示dat文件

2017-05-23 15:03 931 查看

DAT文件的读取

问题描述

之前,博主没有理解dat文件导致对文件获取产生问题和误解,还可笑的认为没办法获取demission的话,是没有办法读取dat文件的。

由于dat文件是遥感影像的常用格式之一。所以,首先认识一番,dat文件。

先找个文件夹看看它在哪



2.看看它们到底长什么样子

hdr 头文件



dat 文件



3.思考怎么去读取dat文件

读取dat文件的思路:

- 首先获取到dat文件的头文件信息。

调用函数进行显示READ_BINARY()



代码实现过程

由于代码实现过于简单,所以没有写相应的注释,有什么不会的直接留言~

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


代码实现的效果



灰度图实现效果



送你们个惊喜

国外优秀网站

在GIS的沙场,传播有价值的东西!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: