IDL中HDF4操作函数
1.首先了解卫星遥感数据的一般组织形式:HDF文件
什么是HDF文件?
- 层次数据格式
- HDF(Hierarchical Data Format),可以存储不同类型的图像和数码数据的文件格式。
2.卫星遥感数据HDF数据一般组织形式:数据集、全局属性、数据集属性
3.IDL常用操作函数
result=hdf_sd_start(filename,[/read|/rdwr] [/create])
打开hdf4文件,返回值是文件的id号(sd_id),filename为文件名,/read表示只读方式,/rdwr表示读写方式,/create表示创建新文件
hdf_sd_fileinfo,sd_id,datasets,attributes
查询hdf4文件信息,datasets为文件包含的数据集的个数,attributes为文件包含的全局属性的个数
result=hdf_sd_select(sd_id,number)
选择hdf4数据集,number为数据集编号(从0开始),返回值为数据集的id(sddataset_id)
hdf_sd_getinfo,sddataset_id,[name=variable] [natts=variable]
查询hdf4数据集的信息,name返回该数据集的名称,natts返回数据集包含的属性个数,其余关键字可自行查看idl帮助
result=hdt_sd_nametoindex(sd_id,sds_name)
获取指定名称的数据集id
hdf_sd_getdata,sddataset_id,data
获取指定数据集id所包含的数据,data为存储该数据的数组变量
hdf_sd_attrinfo,sd_id,attr_index,[data=variable] [name=variable]
查询hdf属性信息,sd_id为hdf文件id或数据集id,attr_index为属性编号(从0开始),name返回该数据集属性名称,data返回属性信息中包含的数据,其余关键字可自行查看idl帮助
hdf_sd_endaccess,sddataset_id
关闭id号为sddataset_id的hdf4数据集
hdf_sd_end,sd_id
关闭id号为sd_id的文件
读取hdf文件的一般步骤:
- 指定文件名
- 打开文件
- 获取数据集/属性名称
- 获取数据集/属性id
- 获取数据集/属性内容
- 下一步处理
示例1:数据信息查询
pro hdf4_file_info_extract
modis_data='E:\BaiduNetdiskDownload\chapter_1\MODIS_2018_mod04_3k\MYD04_3K.A2018122.0450.061.2018124152529.hdf'
sd_id=hdf_sd_start(modis_data,/read)
hdf_sd_fileinfo,sd_id,sds_num,att_num
;print,sds_num
;print,att_num
for sds_i=0,sds_num-1 do begin
sds_id=hdf_sd_select(sd_id,sds_i)
hdf_sd_getinfo,sds_id,name=sds_name,natts=sds_att_num
print,'The sds name of'+strcompress(string(sds_i))+':'
print,sds_name
print,'The included atrributes name:'
if sds_att_num gt 0 then begin
for att_i=0,sds_att_num-1 do begin
hdf_sd_attrinfo,sds_id,att_i,name=sds_att_name
print,sds_att_name
endfor
print,string('*************************************')
endif
hdf_sd_endaccess,sds_id
endfor
for att_i=0,att_num-1 do begin
hdf_sd_attrinfo,sd_id,att_i,name=global_att_name
endfor
hdf_sd_end,sd_id
end
流程图: