pro Part_9
compile_opt idl2
e=envi(/headless)
file_mkdir,"D:\Lansat_Data_综合报告"
glacier_all = float(0.0)
pixel_all_69 = float(0.0)
folder = "D:\Lansat_Data_Ratio\"
envi_arr = file_search(folder,'*.dat',count=num)
arr_out_put = strarr(4,70)
for i=0,num-1,1 do begin
envi_file = envi_arr[i]
envi_name_length = strlen(envi_file)
if (envi_name_length eq 26) then begin
roi_number = strmid(envi_file,21,1)
roi_number_int = fix(strmid(envi_file,21,1))
endif else if (envi_name_length eq 27) then begin
roi_number = strmid(envi_file,21,2)
roi_number_int = fix(strmid(envi_file,21,2))
endif
glacier_pixel = long(0)
raster = e.OpenRaster(envi_file)
fid = ENVIRasterToFID(raster)
MAP_INFO = ENVI_GET_MAP_INFO(fid=fid)
ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb, dims=dim, data_type=data_type
data = raster.getdata()
for l=0,ns-1,1 do begin
for m=0,nl-1,1 do begin
a=data[l,m]
if (a eq 1) then begin
glacier_pixel = glacier_pixel + 1
endif
endfor
endfor
glacier_all = glacier_all + glacier_pixel
all_pixel = long(ns)*nl
pixel_all_69 = pixel_all_69 + all_pixel
percentage = (float(glacier_pixel)/all_pixel)*100
arr_out_put[0,roi_number_int-1] = roi_number;ROI序号
arr_out_put[1,roi_number_int-1] = string(all_pixel);总像素量
arr_out_put[2,roi_number_int-1] = string(glacier_pixel);冰川像素
arr_out_put[3,roi_number_int-1] = string(percentage);冰川百分比
print,envi_file
endfor
percentage_final = (glacier_all/pixel_all_69)*100
arr_out_put[0,69] = "ALL-ROI"
arr_out_put[1,69] = string(pixel_all_69);总像素量
arr_out_put[2,69] = string(glacier_all);冰川像素
arr_out_put[3,69] = string(percentage_Final);冰川百分比
txt_file = "D:\Lansat_Data_综合报告\glacier_report.txt"
openw,lun,txt_file,/get_lun
printf,lun,arr_out_put
free_lun,lun
print,"----------------------OK!!!-----------------------------"
print,txt_file
end
生成冰川面积统计结果
于 2024-06-06 20:37:16 首次发布