| 
 
	积分307贡献 精华在线时间 小时注册时间2015-10-30最后登录1970-1-1 
 | 
 
| 
程序需要加载坐标文件——代码中的:‘1’,问一下,谁知道1从哪来的,在哪里下载
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  PRO AMRS_Menu_Event_define_buttons, buttonInfo
 ENVI_DEFINE_MENU_BUTTON, buttonInfo, VALUE = 'ASMR-E-Main', $
 /MENU, REF_VALUE = 'Basic Tools', /SIBLING, POSITION = 'after'
 ENVI_DEFINE_MENU_BUTTON, buttonInfo, VALUE = 'Main Interface', $
 UVALUE = 'Main', EVENT_PRO = 'YieldPrediction', $
 REF_VALUE = 'ASMR-E-Main', POSITION = 'last'
 end
 pro AMRS_Menu_Event,event
 ;打开HDF文件
 filters = ['*.hdf']
 pathname ='H:\rsdata\AMSR-E\2003\'
 filename = DIALOG_PICKFILE(/READ, FILTER = filters,path=pathname)
 print,filename
 newfilename=STRMID(filename,0,STRLEN(filename)-4)+'_JinZhou';
 print,newfilename;
 ;取标准格式的AMSR坐标文件
 envi_open_file, 'h:\1', r_fid=in_fid
 ENVI_FILE_QUERY, in_fid, ns=ns, nl=nl, nb=nb, fname=fname
 map_info = envi_get_map_info(fid=in_fid)
 ;从HDF文件中取数据,并保存
 ;********************************************
 hdfid = HDF_open(filename); opens HDF file
 ;Checks to make sure the filename is correct and/or a HDF file
 if (hdfid lt 0)then begin
 print, "Incorrect filename"
 stop
 endif
 vdID = 7 ;VData reference number for Land Parameters Data
 vd_handle = HDF_VD_ATTACH(hdfid, vdID, /Read)
 HDF_VD_GET, vd_handle
 ;Read in the following fields from the Land Parameters Table: Row_Index,
 ;Column_Index, Soil_Moisture. This data is read in and stored in variable X
 ;nREC returns the number of records in the table
 nREC = HDF_VD_READ(vd_handle, X,FIELDS="Row_Index,Column_Index,Soil_Moisture")
 row=intarr(nREC)
 col=intarr(nREC)
 soilmoisture=intarr(nREC)
 row(*)=X(0,*)
 col(*)=X(1,*)
 soilmoisture(*)=X(2,*)
 hdf_vd_detach, vd_handle
 HDF_Close,hdfid
 ;Create a grid,which corresponds to the dimensions of the EASE-Grid
 ;global projection to store the data
 nrows=586
 ncolumns=1383
 soilgrid=intarr(ncolumns,nrows)
 ;Set a data value to represent "No Data"
 no_data=-8888
 ;Initialize the whole array to "No Data"
 soilgrid(*,*)= no_data
 ;Loop through the data records to grid soil moisture
 for i=0,nREC-1 do begin
 xrow=row(i)-1
 ycolumn=col(i)-1
 ;Soil moisture will range from 0-500.
 ;-9999 = AMSR-E value for "MISSING DATA"
 soilgrid(ycolumn,xrow)=soilmoisture(i)
 endfor
 bands=SINDGEN(1)
 bands[0]="moisture band"
 wl=dINDGEN(1)
 wl[0]=1.0
 ENVI_WRITE_ENVI_FILE,soilgrid,MAP_INFO=map_info,BNAMES=bands,R_FID=newfid,wl=wl, /IN_MEMORY
 envi_file_mng, id=in_fid, /remove
 ;***********************************************************
 ;进行坐标转换,将坐标转换成地理坐标
 o_proj = ENVI_PROJ_CREATE(/geographic)
 envi_file_query, newfid, ns=ns1, nl=nl1, nb=nb1
 pos  = lindgen(nb1)
 ;print,pos
 dims = [-1l, 0, ns1-1, 0, nl1-1]
 ;dims=[-1l,0, 1382, 0, 585]
 envi_convert_file_map_projection, fid=newfid, $
 pos=pos, dims=dims, o_proj=o_proj, $
 out_name='h:\xiong', warp_method=2,R_FID=n_fid, $
 resampling=0, background=0,/ZERO_EDGE
 envi_file_mng, id=newfid, /remove
 ENVI_FILE_QUERY, n_fid, ns=ns1, nl=nl1, nb=nb1, dims=dims,fname=fname1
 ;print,dims
 ;取矢量文件进行裁减
 evf_id = envi_evf_open('H:\rsdata\洪湖\荆州各县_.evf')
 envi_evf_info, evf_id, num_recs=num_recs,data_type=data_type, projection=projection,layer_name=layer_name
 for i=0,num_recs-1 do begin
 record = envi_evf_read_record(evf_id, i)
 ENVI_CONVERT_PROJECTION_COORDINATES,record[0,*],record[1,*],projection,$
 g_xmap,g_ymap,o_proj
 ENVI_CONVERT_FILE_COORDINATES,n_fid,xvalue,yvalue,g_xmap,g_ymap
 ;ENVI_CONVERT_FILE_COORDINATES,evf_id,record[0,*],record[1,*],
 roi_id = ENVI_CREATE_ROI(ns=ns1, nl=nl1, color=4, name='evfs')
 ENVI_DEFINE_ROI, roi_id, /polygon, xpts=reform(xvalue), ypts=reform(yvalue)
 roi_ids = envi_get_roi_ids()
 ;envi_save_rois, 'h:\test.roi', roi_ids
 ;out_name = 'h:\baodi_mask_2'
 class_values = lindgen(n_elements(roi_ids))+1
 ;
 ;  Call the doit
 ;
 envi_doit, 'envi_roi_to_image_doit', $
 fid=n_fid, roi_ids=roi_ids, class_values=class_values,R_FID=mask_fid, /IN_MEMORY
 pos  = LINDGEN(nb1)
 m_dims = [-1l, min(FIX(xvalue))-1, max(FIX(xvalue)) - 1, min(FIX(yvalue))-1, max(FIX(yvalue)) - 1]
 ;print,m_dims
 m_pos = [0]
 ; Call the 'doit'
 ENVI_MASK_APPLY_DOIT, FID = n_fid, POS = pos, DIMS = m_dims, $
 M_FID = mask_fid, M_POS = m_pos, VALUE = 0, /IN_MEMORY,R_FID=sub_fid
 envi_file_mng, id=n_fid, /remove
 envi_file_mng, id=mask_fid, /remove
 oproj2 = ENVI_PROJ_CREATE (/utm,zone=49)
 envi_file_query, sub_fid, ns=ns2, nl=nl2, nb=nb2
 pos  = lindgen(nb2)
 dims = [-1l, 0, ns2-1, 0, nl2-1]
 envi_convert_file_map_projection, fid=sub_fid, $
 pos=pos, dims=dims,o_proj=oproj2, $
 out_name=newfilename, warp_method=2,R_FID=result_fid, $
 resampling=0, background=0,/ZERO_EDGE
 envi_file_mng, id=sub_fid, /remove
 endfor
 ;
 ; Close the EVF file
 ;
 envi_evf_close, evf_id
 end
 
 | 
 |