pro split
; file='E:\data\xinout\FY3B_MWRID_GBAL_L1_20141214_1950_010KM_MS_result.tif'
; riqi = strsplit(file,'_',/extract)
; riqitonum = fix(riqi[4])
; print,riqi[4]
path='E:\data\newtestout'
files = file_search(path,'*.tif',count=n)
for i=0,n-1 do begin
riqi = strsplit(files[i],'_',/extract)
print,riqi
riqitonum = long(riqi[4])-20121215
print,riqi[4],long(riqi[4]),riqitonum
endfor
end
pro finaltiqu
COMPILE_OPT IDL2,hidden
e=envi(/headless)
path='E:\data\newtestout'
wendu=indgen(20)+1;温度
;判断日期是第几天转化为温度数组下标 写入
fn='C:\Users\Administrator\Desktop\tibtation.csv';
data=READ_CSV(fn,count=nsta,header=header);
point_fid=data.(0);
Lat=data.(1);站点纬度
Lon=data.(2);站点经度
files = file_search(path,'*.tif',count=n)
;print,files
;二维数组存储
h=fltarr(10,nsta*n);nb=10波段数
id=indgen(nsta*n)
wd=fltarr(nsta*n)
datatime=strarr(nsta*n)
pos = 0
for k=0,n-1 do begin
file = files[k]
;print,file
;实际需要的文件是中国区域裁剪重采样500m的数据
;image_fname='E:\data\xinout\FY3B_MWRID_GBAL_L1_20141214_1950_010KM_MS_result.tif';文件路径
;打开文件
ENVI_OPEN_FILE,file,r_fid=fid
;print ,fid
ENVI_FILE_QUERY, fid, dims=dims, nb=nb,bnames = bnames,DATA_TYPE = dt,ns = ns, nl = nl;nb波段数
map_info=ENVI_GET_MAP_INFO(fid=fid)
;print,map_info
i_proj=ENVI_PROJ_CREATE(/geographic,datum='WGS-84')
o_proj=map_info.proj
envi_convert_projection_coordinates,lon,lat,i_proj,$
xmap,ymap,o_proj
;print,lon,lat,i_proj,xmap,ymap,o_proj
;将站点的地图坐标转换为文件坐标
envi_convert_file_coordinates,fid,xf,yf,xmap,ymap
xf=floor(xf)
yf=floor(yf)
;循环读取各个站点dn
;print,i bug在此
for i=0, nsta-1 do begin;站点
dims1=[-1, xf[i], xf[i], yf[i], yf[i]] ;构建空间范围数组DIMS
for j=0 , nb-1 do begin
temp = envi_get_data(fid=fid,dims=dims1,pos=j)
if temp eq 0 or temp eq -999 then begin;-999无效值
;h[j,i*k]=0 ;不能乘 0-0 0-102 0 2 4 - 204 0 3 6 9 - 306只能计数
h[j,pos]=0
endif else begin
h[j,pos]=temp*0.01+327.68
endelse
endfor
riqi = strsplit(file,'_',/extract)
riqitonum = long(riqi[4])
;print,riqitonum
wd[pos]=wendu[riqitonum-20121215]
datatime[pos]=riqi[4]+riqi[5]
pos +=1
endfor
print,file+"-----提取结束!"
endfor
;print,h[0,*];这一天所有站点第一个波段的值
;print,h[1,*];这一天所有站点第二个波段的值
;print,"********************"
;print,h[*,0];这一天第一个站点所有波段的值
;***********保存结果*********
o_fn='E:\data\tiqu.csv';指定存储结果路径
;header=[header,'h1','h2','h3','h4','h5','h6','h7','h8','h9','h10']
header=['id','h1','h2','h3','h4','h5','h6','h7','h8','h9','h10','wendu','datatime']
;data=create_struct(data,'H1',h[0,*],'H2',h[1,*],'H3',h[2,*],'H4',h[3,*],'H5',h[4,*],'H6',h[5,*],'H7',h[6,*],'H8',h[7,*],'H9',h[8,*],'H10',h[9,*]);在data中增加一个value域
data=create_struct('id',id,'H1',h[0,*],'H2',h[1,*],'H3',h[2,*],'H4',h[3,*],'H5',h[4,*],'H6',h[5,*],'H7',h[6,*],'H8',h[7,*],'H9',h[8,*],'H10',h[9,*],'wd',wd,'dt',datatime);在data中增加一个value域
write_csv,o_fn,data,header=header;写入csv
;e.close
end