sunsett的个人博客分享 http://blog.sciencenet.cn/u/sunsett

博文

ENVI/IDL 数据类型转换-以envi与tif为例

已有 9740 次阅读 2020-8-17 22:56 |个人分类:ENVI/IDL|系统分类:科研笔记

最近遇到需要大量tif格式的数据,需要转为envi格式,为减轻机械劳动,这里提供了两种IDL编程

方法:第一种使用的是 面向对象编程的envi raster,第二种使用的是 envi classic :

以envi格式与tif格式互转为例:

envi面向对象编程的方法:关键函数为 enviraster.export

pro y_envi2tif

  ;2020.08.13

  ; convert envi to tif

  compile_opt idl2

  e = ENVI(/headless)

  ;TODO auto-generated stub

  ipath='F:\data'

  filelist=file_search(ipath, '*.hdr', count=countall) ;envi格式的数据    

  for i=0, countall-1 do begin

    file=filelist[i]

    print, 'process:', file

    t1 = SYSTIME(/second)

    resdata=strmid(file,0, strlen(file)-4)+'1.tif'  ;所需要的tif的名称

    if file_test(resdata) eq 0 then begin

        data=e.openraster(file)

        data.export, resdata, 'TIFF' ;

        data.close

        print, 'success:', resdata

      endif

     endfor

     t2 = SYSTIME(/second)

     print, 'success:', file

     print, 'total time: ', t2-t1

   endfor

end


envi classic方法

pro y_tif2envi

  ;2020.08.13

  ; convert tif to envi

  compile_opt idl2

  e = ENVI(/headless)

  ;TODO auto-generated stub

  ipath='F:\data'

  filelist=file_search(ipath, '*.tif', count=countall) 

  for i=0, countall-1 do begin

    file=filelist[i]

    respath = strmid(file, 0, strlen(file)-4)+'1'

    t1 = SYSTIME(/second)

    if file_test(respath) eq 0 then begin    

      print, 'process:', file

      envi_open_file, file, r_fid=ifid

      envi_file_query, ifid, dims=idims

      ENVI_OUTPUT_TO_EXTERNAL_FORMAT, dims=idims, fid=ifid, out_name=respath,/envi, pos=[0]

      envi_file_mng,id = ifid,/remove ;似乎并没有将文件从内存中去除,不知道为什么,待解决

      print, 'success:', file

    endif 

    t2 = SYSTIME(/second)

    print, 'success:', file

    print, 'total time: ', t2-t1

  endfor

end


注:对于classic方法而言,需要打开 envi classic +idl程序,而对于面向对象编程而言,需要打开 envi + idl



https://blog.sciencenet.cn/blog-3409932-1246768.html

上一篇:[转载]sentinel-2数据批量下载
下一篇:ENVI/IDL 批量将16位遥感影像转为8位存储
收藏 IP: 183.226.199.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

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

GMT+8, 2024-4-24 23:24

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部