运行前在控制台启动ENVI。
pro EXAMPLE_MATH_DOIT_Batch
compile_opt IDL2
path = envi_pickfile(/directory) ;打开文件所在路径
files = file_search(path,'*dat',count=count)
if count eq 0 then return
outPath = 'D:\'
for i=0, count-1 do begin
file = files[i]
envi_open_file, file, r_fid=fid
if (fid[0] eq -1) then continue
envi_file_query, fid, dims=dims
t_fid = [fid,fid]
pos = [2,3]
exp = 'bm_CalVFC(b1,b2)'
bname=file_basename(file,'.dat') ;提取不带文件扩展名的的文件名
out_name = outPath + baname + '_ndvi.dat'
; Perform the band math processing
envi_doit, 'math_doit', $
fid=t_fid, pos=pos, dims=dims, $
exp=exp, out_name=out_name, $
r_fid=r_fid
endfor
end
植被覆盖度函数(植被覆盖度计算方法不尽相同,在此选取一种算法用代码实现):
;vfc=bm_CalVFC(red,nir,[min=double(ndvi_min)],[max=double(navi_max)])
function bm_CalVFC,red,nir,min=min,max=max
if ~n_elements(min) then min = 0.05
if ~n_elements(max) then max = 0.7
ndvi=(float(nir)-red)/(float(nir)+red)
vfc=(ndvi lt min)*0+(ndvi gt max)*1+(ndvi ge min and ndvi le max)* $
(ndvi-min)/(max-min)
return,vfc
end