Ejemplo n.º 1
0
        private static void ConvertHdf4To5(Hdf4FileAttrs hdf4FileAttrs, string f5name,
                                           Action <string, int, int> messageAction)
        {
            try
            {
                // Create a new file using H5F_ACC_TRUNC access,
                // default file creation properties, and default file
                // access properties.
                H5FileId fileId = H5F.create(f5name, H5F.CreateMode.ACC_TRUNC);

                int nxf5 = hdf4FileAttrs.Hdf4FileAttr.XDim;
                int nyf5 = hdf4FileAttrs.Hdf4FileAttr.YDim;
                int rank = 2;

                //测试读取的科学数据集及其属性
                int sdscount = hdf4FileAttrs.Hdf4FileAttr.DataFields.Count;
                for (int k = 0; k < sdscount; k++)
                {
                    ConvertHdf4To5BySds(hdf4FileAttrs, messageAction, k, nyf5, nxf5, rank, fileId);
                }

                HDFAttributeDef[] attributeDef5s = hdf4FileAttrs.GetHDFAttributeDefs();
                foreach (HDFAttributeDef attributeDef5 in attributeDef5s)
                {
                    WriteHdfAttributes.WriteHdfAttribute(fileId, attributeDef5);
                }

                H5F.close(fileId);
            }
            catch (Exception ex)
            {
                throw new Exception("拼接Hdf4时出错,具体信息:" + ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        private static void ConvertHdf4To5(Hdf4FileAttrs hdf4FileAttrs, string f5name,
                                           Action <string, int, int> messageAction, SEnvelope outenvelope, float dstResolution,
                                           ISpatialReference dstSpatialReference)
        {
            try
            {
                // Create a new file using H5F_ACC_TRUNC access,
                // default file creation properties, and default file
                // access properties.
                H5FileId fileId = H5F.create(f5name, H5F.CreateMode.ACC_TRUNC);

                int nxf5 = hdf4FileAttrs.Hdf4FileAttr.XDim;
                int nyf5 = hdf4FileAttrs.Hdf4FileAttr.YDim;
                int rank = 2;

                //测试读取的科学数据集及其属性
                int sdscount = hdf4FileAttrs.Hdf4FileAttr.DataFields.Count;

                SEnvelope envelopeNew = null;
                UInt16[]  rows        = null; //正向查找表
                UInt16[]  cols        = null; //正向查找表
                Size      srcStepSize = Size.Empty;
                Size      outSize     = Size.Empty;
                try
                {
                    for (int k = 0; k < sdscount; k++)
                    {
                        ConvertHdf4To5BySds(hdf4FileAttrs, messageAction, k, nyf5, nxf5, rank, fileId, outenvelope, dstResolution, dstSpatialReference, ref rows, ref cols, ref srcStepSize, ref outSize);
                        if (envelopeNew == null && dstSpatialReference != null && outenvelope != null)
                        {
                            envelopeNew = outenvelope;
                        }
                    }
                    if (envelopeNew != null)
                    {
                        hdf4FileAttrs.RefreshPointString(envelopeNew);
                    }
                }
                finally
                {
                    rows        = null;
                    cols        = null;
                    srcStepSize = Size.Empty;
                    GC.Collect();
                }

                HDFAttributeDef[]      attributeDef5s  = hdf4FileAttrs.GetHDFAttributeDefs();
                List <HDFAttributeDef> updateFileAttrs = new List <HDFAttributeDef>();
                updateFileAttrs.AddRange(attributeDef5s);
                if (dstSpatialReference != null && dstSpatialReference.IsSame(SpatialReference.GetDefault()))
                {
                    //投影信息
                    string          projtype    = "Geopraphic Latitude longtitude";
                    HDFAttributeDef projecttype = new HDFAttributeDef("Projection Type", typeof(string), projtype.Length, projtype);
                    updateFileAttrs.Add(projecttype);
                    //写四角坐标信息
                    HDFAttributeDef lefttopY = new HDFAttributeDef("Left-Top Latitude", typeof(float), 1, new float[] { (float)outenvelope.YMax });
                    updateFileAttrs.Add(lefttopY);
                    HDFAttributeDef lefttopX = new HDFAttributeDef("Left-Top Longtitude", typeof(float), 1, new float[] { (float)outenvelope.XMin });
                    updateFileAttrs.Add(lefttopX);
                    HDFAttributeDef boottomrightY = new HDFAttributeDef("Bottom-Right Latitude", typeof(float), 1, new float[] { (float)outenvelope.YMin });
                    updateFileAttrs.Add(boottomrightY);
                    HDFAttributeDef boottomrightX = new HDFAttributeDef("Bottom-Right Longtitude", typeof(float), 1, new float[] { (float)outenvelope.XMax });
                    updateFileAttrs.Add(boottomrightX);
                    HDFAttributeDef xResolution = new HDFAttributeDef("Longtitude Resolution", typeof(float), 1, new float[] { (float)dstResolution });
                    updateFileAttrs.Add(xResolution);
                    HDFAttributeDef yResolution = new HDFAttributeDef("Latitude Resolution", typeof(float), 1, new float[] { (float)dstResolution });
                    updateFileAttrs.Add(yResolution);
                }
                foreach (HDFAttributeDef attributeDef5 in updateFileAttrs)
                {
                    WriteHdfAttributes.WriteHdfAttribute(fileId, attributeDef5);
                }

                H5F.close(fileId);
            }
            catch (Exception ex)
            {
                throw new Exception("拼接Hdf4时出错,具体信息:" + ex.Message, ex);
            }
        }