logo资料库

Shape文件批量裁剪遥感影像软件.docx

第1页 / 共22页
第2页 / 共22页
第3页 / 共22页
第4页 / 共22页
第5页 / 共22页
第6页 / 共22页
第7页 / 共22页
第8页 / 共22页
资料共22页,剩余部分请下载后查看
1 / 22 Shape 文件批量裁剪遥感影像软件 V1.0_源代码 ;测试数据文件路径‘F:\filter_test’ ;批量影像裁剪程序 ;界面设计 ; pro pro_cleanup_event,tlb widget_control,tlb,get_uvalue=pstate ptr_free,pstate end ;事件响应程序 pro batch_clip_images_viashp_win_Event,ev COMPILE_OPT idl2 ENVI, /RESTORE_BASE_SAVE_FILES ENVI_BATCH_INIT widget_control,ev.top,get_uvalue=pstate uname=widget_info(ev.id,/uname) case uname of 'img_open_button':begin (*pstate).img_infile=dialog_pickfile(path='',/directory,$ title='请选择您要裁剪的遥感影像所在的文件夹',DIALOG_PARENT=ev.top, GET_PATH=GET_PATH) widget_control,(*pstate).clip_img_path,set_value=(*pstate).img_infile (*pstate).img_infile=GET_PATH end 'in_lan_format_button':begin widget_control,ev.id,get_value=clip_input_format (*pstate).clip_input_format=strcompress(clip_input_format,/remove_all) end 'in_dat_format_button':begin widget_control,ev.id,get_value=clip_input_format (*pstate).clip_input_format=strcompress(clip_input_format,/remove_all) end 'in_tif_format_button':begin widget_control,ev.id,get_value=clip_input_format (*pstate).clip_input_format=strcompress(clip_input_format,/remove_all) end 'in_jpg_format_button':begin widget_control,ev.id,get_value=clip_input_format (*pstate).clip_input_format=strcompress(clip_input_format,/remove_all) end 'out_lan_format_button':begin widget_control,ev.id,get_value=clip_output_format (*pstate).clip_output_format=strcompress(clip_output_format,/remove_all) end 'out_dat_format_button':begin widget_control,ev.id,get_value=clip_output_format (*pstate).clip_output_format=strcompress(clip_output_format,/remove_all) end 'out_tif_format_button':begin
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 2 / 22 widget_control,ev.id,get_value=clip_output_format (*pstate).clip_output_format=strcompress(clip_output_format,/remove_all) end 'out_jpg_format_button':begin widget_control,ev.id,get_value=clip_output_format (*pstate).clip_output_format=strcompress(clip_output_format,/remove_all) end 'shape_open_button':begin (*pstate).shape_infile=dialog_pickfile(title='选择您需要的 shape 文件',$ filter='*.shp',DIALOG_PARENT=ev.top) widget_control,(*pstate).shape_path,set_value=(*pstate).shape_infile end 'ascii_yes_button':begin widget_control,ev.id,get_value=ASCII_file (*pstate).ASCII_file=strcompress(ASCII_file,/remove_all) end 'ascii_no_button':begin widget_control,ev.id,get_value=ASCII_file (*pstate).ASCII_file=strcompress(ASCII_file,/remove_all) end 'suffix_text':begin widget_control,ev.id,get_value=file_name_input (*pstate).file_name_input=file_name_input end 'clip_button':begin if (*pstate).img_infile eq '' then begin result=dialog_message('请选择需要裁剪的文件路径',title='错误',/error) return endif if (*pstate).shape_infile eq '' then begin result=dialog_message('请选择裁剪影像的 shape 文件',title='错误',/error) return endif if (*pstate).clip_input_format eq '' then begin result=dialog_message('请选择输入文件格式',/error) return endif if (*pstate).clip_output_format eq '' then begin result=dialog_message('请选择输出文件格式',/error) return endif if (*pstate).ASCII_file eq '' then begin result=dialog_message('请选择是否需要输出 ASCII 文件',title='错误',/error) return endif void=dialog_message('确定裁剪后文件后缀名为'+(*pstate).file_name_input,/information)
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 3 / 22 raster_clip_viashape_tiff,(*pstate).img_infile,(*pstate).shape_infile,$ (*pstate).clip_input_format,(*pstate).clip_output_format,(*pstate).$ file_name_input,(*pstate).ASCII_file end 'cancel_button':begin widget_control,ev.top,/DESTROY end endcase end ;建立窗口主程序 pro batch_clip_images_viashp_win ;建立窗体 tlb=widget_base(title='Shape 文件批量裁剪遥感影像软件',/COLUMN) ;通过 shape 文件筛选空间范围数据模块 clip_img_base ; clip_img_label=widget_label(clip_img_base,$ = widget_base(tlb,/column,/frame) value='通过 shape 文件批量裁剪遥感影像') ;打开标签及其按钮 img_base=widget_base(clip_img_base,/column,/frame) img_open_base=widget_base(img_base,/row) clip_img_label = widget_label(img_open_base,$ value=' 请选择您要裁剪的遥感影像所在的文件夹') img_path_button = widget_button(img_open_base,value='open.bmp',$ /bitmap,uname='img_open_button') ;路径存放的窗口 clip_img_path = widget_text(img_base,value='',xsize=64,$ uname='clip_img_path') ;裁剪影像数据文件输入格式和输出格式设定 ;格式存放窗口 format_base=widget_base(clip_img_base,/column,/frame) ;输入格式存放窗口 informat_base=widget_base(format_base,/row,/frame) input_format_label= widget_label(informat_base,$ value=' 请选择输入文件格式 ') input_format_base = WIDGET_BASE(informat_base,$ /EXCLUSIVE,/row,/frame) lan_format = WIDGET_BUTTON(input_format_base,value ='.pix',$ uName = 'in_lan_format_button',/NO_RELEASE ) dat_format = WIDGET_BUTTON(input_format_base,value ='.dat',$ uName = 'in_dat_format_button',/NO_RELEASE ) tif_format = WIDGET_BUTTON(input_format_base,value ='.tif',$ uName = 'in_tif_format_button',/NO_RELEASE ) jpg_format = WIDGET_BUTTON(input_format_base,value ='.jp2',$ uName = 'in_jpg_format_button',/NO_RELEASE )
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 4 / 22 ;输出格式存放窗口 outformat_base=widget_base(format_base,/row,/frame) output_format_label= widget_label(outformat_base,$ value=' 请选择输出文件格式 ') output_format_base = WIDGET_BASE(outformat_base,$ /EXCLUSIVE,/row,/frame) lan_format = WIDGET_BUTTON(output_format_base,value ='.pix',$ uName = 'out_lan_format_button',/NO_RELEASE ) dat_format = WIDGET_BUTTON(output_format_base,value ='.dat',$ uName = 'out_dat_format_button',/NO_RELEASE ) tif_format = WIDGET_BUTTON(output_format_base,value ='.tif',$ uName = 'out_tif_format_button',/NO_RELEASE ) jpg_format = WIDGET_BUTTON(output_format_base,value ='.jp2',$ uName = 'out_jpg_format_button',/NO_RELEASE,/menu ) ; ; 湿地任务专项 wetland_base=widget_base(format_base,/frame,/row) wetland_label=widget_label(wetland_base,value=' 请输入裁剪后生成文件后缀名 wetland_label=widget_text(wetland_base,value='clip',uname='suffix_text',/editable) ; ;ACII 文件选项 ; ascii_file_base=widget_base(format_base,/frame,/row) ascii_file_label=widget_label(ascii_file_base,value=' 是否生成 ASCII 文件? ') ascii_file_select_base=widget_base(ascii_file_base,/EXCLUSIVE,/row) ascii_yes_button=widget_button(ascii_file_select_base,value='Yes',$ uname='ascii_yes_button',/NO_RELEASE) ascii_no_button=widget_button(ascii_file_select_base,value='No',$ uname='ascii_no_button',/NO_RELEASE) ') ;打开 shape 文件界面 shape_base=widget_base(clip_img_base,/column,/frame) shape_open_base=widget_base(shape_base,/row) shape_label = widget_label(shape_open_base,$ value=' 请选择您用于裁剪的 shape 文件') shape_path_button = widget_button(shape_open_base,$ value='open.bmp',/bitmap,uname='shape_open_button') shape_path = widget_text(shape_base,value='',xsize=64,$ uname='shape_path') clip_button=widget_button(clip_img_base,$ value='执行 shape 文件批量数据裁剪',$ uname='clip_button') cancel_button=widget_button(clip_img_base,$ value='取消操作',$ uname='cancel_button')
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 5 / 22 img_infile='' shape_infile='' widget_control,tlb,/realize ASCII_file='' file_name_input='clip' clip_input_format='' clip_output_format='' state={clip_img_path:clip_img_path,$ shape_path:shape_path,$ clip_input_format:clip_input_format,$ clip_output_format:clip_output_format,$ img_infile:img_infile,$ shape_infile:shape_infile,$ file_name_input:file_name_input,$ ASCII_file:ASCII_file} pstate=ptr_new(state,/no_copy) widget_control,tlb,set_uvalue=pstate,/realize ;获取显示器大小以及窗口大小使弹出窗口居中显示 device,get_screen_size=ss window_info=widget_info(tlb,/geometry) tlbXY=[window_info.scr_xsize,$ window_info.scr_ysize] offset_XY=(SS-tlbXY)/2 offset_X=offset_XY[0] offset_Y=offset_XY[1] widget_control,tlb,xoffset=offset_X,$ yoffset=offset_Y ;响应事件 XManager,'batch_clip_images_viashp_win',tlb,$ cleanup='pro_cleanup_event',$ EVENT_HANDLER='batch_clip_images_viashp_win_Event',/no_block End pro raster_clip_viashape_tiff,in_folder,shpFile,$ fileextension,outputextension,file_name_input,ASCII_file COMPILE_OPT idl2 ENVI, /RESTORE_BASE_SAVE_FILES ENVI_BATCH_INIT in_folder=envi_pickfile(title='选择您要裁剪的文件夹',default='F:\filter_test\HLL\dat',/directory) fileextension='.dat' inputextension='_TOAref' ; ; ; ; outputextension='.tif' ; ; ASCII_file='Yes' file_name_input='_裁剪' imgfile_arr=FILE_SEARCH(in_folder,'*'+fileextension,$
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 6 / 22 ; ; ; /FOLD_CASE,COUNT=img_num) IF(img_num EQ 0) THEN BEGIN void=DIALOG_MESSAGE('没有您需要的文件类型:',/error) RETURN ENDIF ; ;选择 shape 文件 shpFile=ENVI_PICKFILE(title='选择您需要的 shape 文件',default='J:\影像裁剪程序测试\shape',$ filter='*.shp') ;输出文件夹 in_folder_dir=file_dirname(in_folder) in_folder_bas=file_basename(in_folder) out_Folder=in_folder_dir+PATH_SEP()+in_folder_bas+strcompress(file_name_input,/remove_all)$ +PATH_SEP() file_mkdir,out_Folder ;创建一个进度条 tlb=widget_base(map=0) ;IDL 的 iTools 自带进度条 prsbar = IDLITWDPROGRESSBAR(GROUP_LEADER=tlb,title ='Progressing',$ CANCEL=cancelIn) ; log_file=out_Folder+'log.txt' openw,log_lun,log_file,/get_lun,width=300 ; finish_cnts=0 ; whole_bandnames=['band1','band2','band3','band4','band5','band6','band7'] FOR img_i = 0,img_num-1 DO BEGIN ;开始处理时系统时间 start=systime(1) ;记录总的处理数据量 finish_cnts++ ;打开影像数据 flag_qua=0 envi_open_data_file,imgfile_arr[img_i],r_fid=fid,/tiff,/envi,/envisat,$ /imagine,/jp2,/jpeg,/pci imgfile_bas=file_basename(imgfile_arr[img_i],fileextension) ;报错系统 CATCH, err IF (err NE 0) THEN BEGIN CATCH, /CANCEL PRINT, 'ERROR: ' + !ERROR_STATE.MSG MESSAGE, /RESET RETURN ENDIF ;查询文件信息 ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb, $
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 7 / 22 dims=dims, fname=fname, bnames=bnames,wl=wl = LINDGEN(nb) = 1 pos inside outFile = envi_get_tmp() sensor=strmid(imgfile_bas,0,3) case sensor of 'LM4':begin bandnames=strarr(nb) for i_band=0, nb-1 do begin if wl[0] eq -1 then begin bandnames=whole_bandnames[0:nb-1] continue endif case 1 of ((wl[i_band] gt 0.5) and (wl[i_band] lt 0.6)):begin $ bandnames[i_band]='Blue' end ((wl[i_band] gt 0.6) and (wl[i_band] lt 0.7)):begin $ bandnames[i_band]='Green' end ((wl[i_band] gt 0.7) and (wl[i_band] lt 0.8)):begin $ bandnames[i_band]='Red' end ((wl[i_band] gt 0.8) and (wl[i_band] lt 1.1)):begin $ bandnames[i_band]='NIR' end else:begin bandnames=whole_bandnames[0:nb-1] end endcase endfor Year=fix(strmid(imgfile_bas,9,4)) end 'LM5':begin bandnames=strarr(nb) for i_band=0, nb-1 do begin if wl[0] eq -1 then begin bandnames=whole_bandnames[0:nb-1] continue endif case 1 of ((wl[i_band] gt 0.5) and (wl[i_band] lt 0.6)):begin $ bandnames[i_band]='Blue' end ((wl[i_band] gt 0.6) and (wl[i_band] lt 0.7)):begin $
Shape 文件批量裁剪遥感影像软件 V1.0_源代码 8 / 22 bandnames[i_band]='Green' end ((wl[i_band] gt 0.7) and (wl[i_band] lt 0.8)):begin $ bandnames[i_band]='Red' end ((wl[i_band] gt 0.8) and (wl[i_band] lt 1.1)):begin $ bandnames[i_band]='NIR' end else:begin bandnames=whole_bandnames[0:nb-1] end endcase endfor Year=fix(strmid(imgfile_bas,9,4)) end 'LT4':begin bandnames=strarr(nb) for i_band=0, nb-1 do begin if wl[0] eq -1 then begin bandnames=whole_bandnames[0:nb-1] continue endif case 1 of (wl[i_band] gt 0.45) and (wl[i_band] lt 0.52):begin $ bandnames[i_band]='Blue' end (wl[i_band] gt 0.52) and (wl[i_band] lt 0.6):begin $ bandnames[i_band]='Green' end (wl[i_band] gt 0.63) and (wl[i_band] lt 0.69):begin $ bandnames[i_band]='Red' end (wl[i_band] gt 0.76) and (wl[i_band] lt 0.9):begin $ bandnames[i_band]='NIR' end (wl[i_band] gt 1.55) and (wl[i_band] lt 1.75):begin $ bandnames[i_band]='SWIR1' end (wl[i_band] gt 10.4) and (wl[i_band] lt 12.5):begin $ bandnames[i_band]='MWIR' end (wl[i_band] gt 2.08) and (wl[i_band] lt 2.35):begin $ bandnames[i_band]='SWIR2' end else:begin bandnames=whole_bandnames[0:nb-1] end
分享到:
收藏