Beispiel #1
0
        private static bool OutputL1FileByOne(string hdfFile, string outDir, ref string error)
        {
            string L1GBALDataSetsStr   = GetL1GBALDataset(false);
            IRasterDataProvider srcPrd = HDF5Driver.Open(hdfFile, enumDataProviderAccess.ReadOnly, new string[] { L1GBALDataSetsStr }) as IRasterDataProvider;

            if (srcPrd.BandCount == 0)
            {
                srcPrd.Dispose();
                L1GBALDataSetsStr = GetL1GBALDataset(true);
                srcPrd            = HDF5Driver.Open(hdfFile, enumDataProviderAccess.ReadOnly, new string[] { L1GBALDataSetsStr }) as IRasterDataProvider;
            }
            float[] data       = null;
            float[] lon        = null;
            float[] lat        = null;
            string  outDirBase = outDir + "\\L1GBAL\\";
            Size    srSize     = Size.Empty;

            try
            {
                GetBandData(srcPrd, srcPrd.BandCount - 1, ref lon, ref srSize);
                GetBandData(srcPrd, srcPrd.BandCount, ref lat, ref srSize);
                for (int bandNo = 1; bandNo <= srcPrd.BandCount - 2; bandNo++)
                {
                    IBandProvider srcbandpro = srcPrd.BandProvider as IBandProvider;
                    {
                        IRasterBand latBand = srcPrd.GetRasterBand(bandNo);
                        {
                            srSize = new Size(latBand.Width, latBand.Height);
                            data   = new float[srSize.Width * srSize.Height];
                            unsafe
                            {
                                fixed(float *ptrLat = data)
                                {
                                    IntPtr bufferPtrLat = new IntPtr(ptrLat);

                                    latBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLat, enumDataType.Float, srSize.Width, srSize.Height);
                                }
                            }
                        }
                        string outFilename = "band_" + bandNo + ".txt";
                        WriteL1GBALFile(outDirBase + Path.GetFileNameWithoutExtension(hdfFile) + "\\", outFilename, data, lon, lat, srSize);
                    }
                }
            }
            catch (Exception ex)
            {
                error += hdfFile + ": " + ex.Message + "\n";
                return(false);
            }
            finally
            {
                data = null;
                srcPrd.Dispose();
                GC.SuppressFinalize(false);
            }
            return(true);
        }
Beispiel #2
0
        public bool Reverse(string srcFileName, string dstFileName)
        {
            if (string.IsNullOrEmpty(srcFileName) || !File.Exists(srcFileName))
            {
                return(false);
            }
            //风速、u分量、v分量、海面温度、降雨量、大气水汽含量、云中液态水含量
            string[] args = new string[] { "datasets=ssw_f16f17rmsm,u_sm,v_sm," +
                                           "sst_rm,rain_f16f17rm,wv_f16f17rm,clw_f16f17rm" };
            IRasterDataProvider dataPrd    = null;
            IRasterDataProvider dstDataPrd = null;

            try
            {
                dataPrd = HDF5Driver.Open(srcFileName, enumDataProviderAccess.ReadOnly, args) as IRasterDataProvider;
                if (dataPrd == null)
                {
                    return(false);
                }
                else
                {
                    try
                    {
                        dstDataPrd = CreatOutRaster(dstFileName, dataPrd);
                        SetBandsValue(dataPrd, dstDataPrd);
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            finally
            {
                if (dataPrd != null)
                {
                    dataPrd.Dispose();
                }
                if (dstDataPrd != null)
                {
                    dstDataPrd.Dispose();
                }
            }
        }