C#读取风云卫星(HDF5格式)遥感数据的部分代码.doc_第1页
C#读取风云卫星(HDF5格式)遥感数据的部分代码.doc_第2页
C#读取风云卫星(HDF5格式)遥感数据的部分代码.doc_第3页
C#读取风云卫星(HDF5格式)遥感数据的部分代码.doc_第4页
C#读取风云卫星(HDF5格式)遥感数据的部分代码.doc_第5页
免费预览已结束,剩余13页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

using System;using System.Collections.Generic;using System.Linq;using System.Text;using HDF5DotNet;using System.Collections;namespace ReadHDF5 /* * 2011.2.14 xyj * 数据集操作:主要有:在指定群组中获取所有的数据集名称,获取指定名称的数据集的数据 * */ /得到hdf5数据集的数据,主要为int数组,float、double数组保存 class GetHdf5DataSet #region 获取数据集数据,主要包含int,float,double private Array _dataSet; public Array get_Hdf5DataSet get return _dataSet; / / 得到int类型的数据集 / / 文件名称,包含路径 / 数据集所在的群组 / 数据集的名称 / 输出的结果数据集 public void hdf5_getDataSet(string fileName, string GroupName, string DsName, int, , dataSet) H5FileId fileId = H5F.open(fileName, H5F.OpenMode.ACC_RDONLY); H5GroupId groupId = H5G.open(fileId, GroupName); H5DataSetId dataSetId = H5D.open(groupId, DsName/*EV_Emissive*/); H5DataTypeId tid0 = H5D.getType(dataSetId); H5DataTypeId tid1 = H5T.enumCreate(tid0);/= new H5DataTypeId(H5T.H5Type.NATIVE_INT);/数据类型 / Read the array back H5D.read(dataSetId, tid1, new H5Array(dataSet);/(dataSetId, tid1, new H5Array(vlReadBackArray); H5D.close(dataSetId); H5G.close(groupId); H5F.close(fileId); _dataSet = dataSet; / / 得到float类型的数据集 / / 文件名称,包含路径 / 数据集所在的群组 / 数据集的名称 / 输出的float结果数据集 public void hdf5_getDataSet(string fileName, string GroupName, string DsName, float, , dataSet) H5FileId fileId = H5F.open(fileName, H5F.OpenMode.ACC_RDONLY); H5GroupId groupId = H5G.open(fileId, GroupName); H5DataSetId dataSetId = H5D.open(groupId, DsName/*EV_Emissive*/); H5DataTypeId tid1 = new H5DataTypeId(H5T.H5Type.NATIVE_FLOAT); / Read the array back H5D.read(dataSetId, tid1, new H5Array(dataSet);/(dataSetId, tid1, new H5Array(vlReadBackArray); H5D.close(dataSetId); H5G.close(groupId); H5F.close(fileId); / / 得到double类型的数据集 / / 文件名称,包含路径 / 数据集所在的群组 / 数据集的名称 / 输出的结果数据集double public void hdf5_getDataSet(string fileName, string GroupName, string DsName, double, , dataSet) H5FileId fileId = H5F.open(fileName, H5F.OpenMode.ACC_RDONLY); H5GroupId groupId = H5G.open(fileId, GroupName); H5DataSetId dataSetId = H5D.open(groupId, DsName/*EV_Emissive*/); H5DataTypeId tid1 = new H5DataTypeId(H5T.H5Type.NATIVE_DOUBLE); / Read the array back H5D.read(dataSetId, tid1, new H5Array(dataSet);/(dataSetId, tid1, new H5Array(vlReadBackArray); H5D.close(dataSetId); H5G.close(groupId); H5F.close(fileId); / / 得到int数据集 / / 文件id / 群组id / 数据集id / int类型的数据集 public void hdf5_getDataSet(H5FileId fileId, H5GroupId groupId, H5DataSetId dataSetId, int, , dataSet) H5DataTypeId tid1 = new H5DataTypeId(H5T.H5Type.NATIVE_INT);/数据类型 / Read the array back H5D.read(dataSetId, tid1, new H5Array(dataSet);/(dataSetId, tid1, new H5Array(vlReadBackArray); _dataSet = dataSet; / / 得到float数据集 / / 文件id / 群组id / 数据集id / float类型的数据集 public void hdf5_getDataSet(H5FileId fileId, H5GroupId groupId, H5DataSetId dataSetId, float, , dataSet) H5DataTypeId tid1 = new H5DataTypeId(H5T.H5Type.NATIVE_FLOAT);/数据类型 / Read the array back H5D.read(dataSetId, tid1, new H5Array(dataSet);/(dataSetId, tid1, new H5Array(vlReadBackArray); _dataSet = dataSet; / / 得到double数据集 / / 文件id / 群组id / 数据集id / double类型的数据集 public void hdf5_getDataSet(H5FileId fileId, H5GroupId groupId, H5DataSetId dataSetId, double, , dataSet) H5DataTypeId tid1 = new H5DataTypeId(H5T.H5Type.NATIVE_DOUBLE);/数据类型 / Read the array back H5D.read(dataSetId, tid1, new H5Array(dataSet);/(dataSetId, tid1, new H5Array(vlReadBackArray); _dataSet = dataSet; /- #endregion / / 获取群组中所有的数据集名称 / / 文件名 / 群组名 / public string getDatasetNames(string filename, string GroupName) / filename = D:FY_dataFY3A_VIRRX_GBAL_L1_20090503_0240_1000M_MS.HDF; H5FileId fileId = H5F.open(filename, H5F.OpenMode.ACC_RDONLY); H5GroupId groupId = H5G.open(fileId, /); ulong num_objs = H5G.getNumObjects(groupId); int num = Convert.ToInt32(num_objs); string dataNames = new stringnum; for (int i = 0; i num; i+) string name = H5G.getObjectNameByIndex(groupId, i); dataNamesi = name; H5G.close(groupId); H5F.close(fileId); return dataNames; /* * 2011.2.14 xyj * 功能:获取群组中所有的属性名 获取属性名的属性值 * * */ class Hdf5AttributeData Array _array; #region /- 获取群组中所有的属性名称attributeNames- / / 得到群组中所有属性字段名,Function used with H5A.iterate / / / / / / static H5IterationResult MyH5AFunction( H5AttributeId attributeId, String attributeName, H5AttributeInfo info, Object attributeNames) / Console.WriteLine(Iteration attribute is 0, attributeName); ArrayList nameList = (ArrayList)attributeNames; nameList.Add(attributeName); / Returning SUCCESS means that iteration should continue to the / next attribute (if one exists). return H5IterationResult.SUCCESS; / / 返回群组中所有的属性名称 / / 群组id号 / public ArrayList getAttributeNames(H5ObjectWithAttributes dataSetId) H5AIterateDelegate attributeDelegate; attributeDelegate = MyH5AFunction; ArrayList attributeNames = new ArrayList(); ulong position = 0; H5A.iterate(dataSetId, H5IndexType.CRT_ORDER, H5IterationOrder.INCREASING, ref position, attributeDelegate, (object)attributeNames); return attributeNames; /- #endregion #region 获取属性值 / / 得到属性值,不足,不能得到rank为的值,返回值也不好获取 / / 可以为groupID,dataSetId / public Array getAttributeValue(H5ObjectWithAttributes dataSetId, string atrrName) H5AttributeId attributeId = H5A.openName(dataSetId, atrrName); /根据属性名称得到属性Id H5DataTypeId attributeType = H5A.getType(attributeId); /得到属性数据类型 H5T.H5TClass tcls = H5T.getClass(attributeType); /类型名称 uint size = H5T.getSize(attributeType); H5T.H5Type H5type; string typeName = tcls.ToString(); H5DataSpaceId spaceid2 = H5A.getSpace(attributeId); ulong dimsA = H5S.getSimpleExtentDims(spaceid2); int rank = H5S.getSimpleExtentNDims(spaceid2); / object readBackRamp = new objectdimsA0; switch (typeName) case FLOAT: if (size 4) H5type = H5T.H5Type.NATIVE_DOUBLE; if (rank = 1) double tmp = new DoubledimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) double, tmp = new DoubledimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else H5type = H5T.H5Type.NATIVE_FLOAT; if (rank = 1) float tmp = new floatdimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) float, tmp = new floatdimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; break; case STRING: H5type = H5T.H5Type.C_S1; if (rank = 1) H5type = H5T.H5Type.C_S1; string tmp = new stringdimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) string, tmp = new stringdimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; break; case INTEGER: H5type = H5T.H5Type.NATIVE_INT; if (rank = 1) int tmp = new intdimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) int, tmp = new intdimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; break; default: H5type = H5T.H5Type.C_S1; if (rank = 1) string tmp = new stringdimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) string, tmp = new stringdimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; break; H5A.close(attributeId); return _array; / / 获取属性值 / / 群组id或数据集id / 属性id / public Array getAttributeValue(H5ObjectWithAttributes dataSetId, H5AttributeId attributeId) H5DataTypeId attributeType = H5A.getType(attributeId); /得到属性数据类型 H5T.H5TClass tcls = H5T.getClass(attributeType); /类型名称 uint size = H5T.getSize(attributeType); H5T.H5Type H5type; string typeName = tcls.ToString(); H5DataSpaceId spaceid2 = H5A.getSpace(attributeId); ulong dimsA = H5S.getSimpleExtentDims(spaceid2); int rank = H5S.getSimpleExtentNDims(spaceid2); / object readBackRamp = new objectdimsA0; switch (typeName) case FLOAT: if (size 4) H5type = H5T.H5Type.NATIVE_DOUBLE; if (rank = 1) double tmp = new DoubledimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) double, tmp = new DoubledimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else H5type = H5T.H5Type.NATIVE_FLOAT; if (rank = 1) float tmp = new floatdimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) float, tmp = new floatdimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; break; case STRING: H5type = H5T.H5Type.C_S1; if (rank = 1) H5type = H5T.H5Type.C_S1; string tmp = new stringdimsA0; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; else if (rank = 2) string, tmp = new stringdimsA0, dimsA1; H5A.read(attributeId, new H5DataTypeId(H5type), /读取属性值 new H5Array(tmp); _array = tmp; break; case INTEGER: H5type = H5T.H5Type.NATIVE_INT; if

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论