桃之夭夭分享 http://blog.sciencenet.cn/u/yelloworld

博文

根据参考对照txt文件对栅格数据进行重新编码

已有 3957 次阅读 2010-7-30 08:30 |个人分类:ENVI/IDL|系统分类:科研笔记

;*Usage:根据参考对照txt文件对栅格数据进行重新编码
;参考文件---Ref_file
;参考文件中的line数目---line_num
;栅格文件---LC_img(为envi standard file)
;输出文件---outfile
pro LCLU_ID_Transform,ref_file,line_num,LC_img,outfile
 temp=' '
;*get the  "Ref-file" in
 openr,lun1,ref_file,/get_lun
 ;jump the first line
 readf,lun1,temp
 LC_ID=intarr(line_num)
 SYS_ID=intarr(line_num)
 for i=1,line_num do begin
  readf,lun1,temp
  records=strsplit(temp,string(9B),/extract)
  LC_ID(i-1)=fix(records[0])
  SYS_ID(i-1)=fix(records[1])
 endfor
 close,lun1
 free_lun,lun1
;*get the LC_img_arcgis in
 envi_open_file,r_fid=fid,LC_img
 if fid eq -1 then begin
     message,'Cannot open file '+LC_img
 endif
 envi_file_query,fid,ns=ns,nl=nl,nb=nb,data_type=d_type
 dims=[-1,0,ns-1,0,nl-1]
 img=bytarr(ns,nl)
 img1=bytarr(ns,nl)
    img=envi_get_data(fid=fid,dims=dims,pos=0)
;*process the lCLU data map
 for i=1,line_num do begin
  index=where(img eq SYS_ID(i-1),count)
  if count gt 0 then begin
   img1[index]=LC_ID(i-1)
  endif
 endfor
;*output the image
 openw,lun,outfile,/get_lun
 writeu,lun,img1
 free_lun,lun
 close,lun
 map_info=envi_get_map_info(fid=fid)
 envi_setup_head, fname=outfile, ns=ns, nl=nl, nb=1, $
        data_type=d_type, interleave=0, map_info=map_info, /write, $
     descrip='LCLU Map'
end


https://blog.sciencenet.cn/blog-219445-348425.html

上一篇:VBA读取word文档表格中table的cell的text文本
下一篇:自动设置更改EXCEL的页眉文字
收藏 IP: .*| 热度|

0

发表评论 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 08:52

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部