||
最近遇到需要大量tif格式的数据,需要转为envi格式,为减轻机械劳动,这里提供了两种IDL编程
方法:第一种使用的是 面向对象编程的envi raster,第二种使用的是 envi classic :
以envi格式与tif格式互转为例:
envi面向对象编程的方法:关键函数为 enviraster.export
pro y_envi2tif
;2020.08.13
; convert envi to tif
compile_opt idl2
e = ENVI(/headless)
;TODO auto-generated stub
ipath='F:\data'
filelist=file_search(ipath, '*.hdr', count=countall) ;envi格式的数据
for i=0, countall-1 do begin
file=filelist[i]
print, 'process:', file
t1 = SYSTIME(/second)
resdata=strmid(file,0, strlen(file)-4)+'1.tif' ;所需要的tif的名称
if file_test(resdata) eq 0 then begin
data=e.openraster(file)
data.export, resdata, 'TIFF' ;
data.close
print, 'success:', resdata
endif
endfor
t2 = SYSTIME(/second)
print, 'success:', file
print, 'total time: ', t2-t1
endfor
end
envi classic方法
pro y_tif2envi
;2020.08.13
; convert tif to envi
compile_opt idl2
e = ENVI(/headless)
;TODO auto-generated stub
ipath='F:\data'
filelist=file_search(ipath, '*.tif', count=countall)
for i=0, countall-1 do begin
file=filelist[i]
respath = strmid(file, 0, strlen(file)-4)+'1'
t1 = SYSTIME(/second)
if file_test(respath) eq 0 then begin
print, 'process:', file
envi_open_file, file, r_fid=ifid
envi_file_query, ifid, dims=idims
ENVI_OUTPUT_TO_EXTERNAL_FORMAT, dims=idims, fid=ifid, out_name=respath,/envi, pos=[0]
envi_file_mng,id = ifid,/remove ;似乎并没有将文件从内存中去除,不知道为什么,待解决
print, 'success:', file
endif
t2 = SYSTIME(/second)
print, 'success:', file
print, 'total time: ', t2-t1
endfor
end
注:对于classic方法而言,需要打开 envi classic +idl程序,而对于面向对象编程而言,需要打开 envi + idl
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-4-24 23:24
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社