Example #1
0
        void item_Click(object sender, EventArgs e)
        {
            RadMenuItem item = sender as RadMenuItem;

            if (item == null)
            {
                return;
            }
            IGeoDataDriver driver = item.Tag as IGeoDataDriver;

            if (driver == null)
            {
                return;
            }
            using (OpenFileDialog diag = new OpenFileDialog())
            {
                diag.Title = "文件打开为" + driver.FullName;
                if (diag.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        IGeoDataProvider provider = driver.Open(diag.FileName, enumDataProviderAccess.ReadOnly);
                        if (provider == null)
                        {
                            return;
                        }
                        OpenDataProvider(provider);
                    }
                    catch (Exception ex)
                    {
                        MsgBox.ShowInfo("无法识别为该驱动的文件" + driver.FullName);
                    }
                }
            }
        }
Example #2
0
        public unsafe void ReadMvgFile_noOffset_Bigger()
        {
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.NotNull(prd);
            IRasterBand band = prd.GetRasterBand(1);

            Assert.NotNull(band);
            Int16[] data = new Int16[prd.Width * 2 * prd.Height];
            Console.WriteLine("prd.Width = " + prd.Width);
            Console.WriteLine("prd.Height = " + prd.Height);
            Console.WriteLine("band.Width = " + band.Width);
            Console.WriteLine("band.Height= " + band.Height);
            fixed(Int16 *ptr = data)
            {
                IntPtr buffer = new IntPtr(ptr);

                band.Read(0, 0, prd.Width, prd.Height, buffer, enumDataType.Int16, prd.Width * 2, prd.Height);
            }

            string dstFname = @"e:\mvg";//@"C:\工作\3.13\read";

            WriteBandToFile(data, dstFname + "_bigger" + "_read" + ".dat");
            prd.Dispose();
            drv.Dispose();
        }
Example #3
0
        public unsafe void ReadMvgFileNormal()
        {
            // _fname = @"C:\工作\3.13\SNW_DBLV_FY3A_VIRR_1000M_NULL_P001_200911131356.mvg";
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.NotNull(prd);
            IRasterBand band = prd.GetRasterBand(1);

            Assert.NotNull(band);
            Int16[] data = new Int16[prd.Width * prd.Height];
            Console.WriteLine("prd.Width = " + prd.Width);
            Console.WriteLine("prd.Height = " + prd.Height);
            Console.WriteLine("band.Width = " + band.Width);
            Console.WriteLine("band.Height= " + band.Height);
            fixed(Int16 *ptr = data)
            {
                IntPtr buffer = new IntPtr(ptr);

                band.Read(0, 0, prd.Width, prd.Height, buffer, enumDataType.Int16, prd.Width, prd.Height);
            }

            string dstFname = @"e:\mvg";//@"C:\工作\3.13\read";

            WriteBandToFile(data, dstFname + "_normal" + "_read" + ".dat");
            prd.Dispose();
            drv.Dispose();
        }
Example #4
0
        public void OpenFile()
        {
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fileName, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.IsNotNull(prd);
            MvgHeader header = (prd as IMvgDataProvider).Header as MvgHeader;

            Assert.IsNotNull(header);
            Console.WriteLine("header.Width=" + header.Width);
            Console.WriteLine("header.Height=" + header.Height);
            HdrFile hdr = header.ToHdrFile();

            PrintHdrInfo(hdr);
        }
        public unsafe void WriteMvgFileNormal()
        {
            // _fname = @"C:\工作\3.13\SNW_DBLV_FY3A_VIRR_1000M_NULL_P001_200911131356.mvg";
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.NotNull(prd);
            IRasterBand band = prd.GetRasterBand(1);

            Assert.NotNull(band);
            Int16[] buffer = new Int16[prd.Width * prd.Height];
            Console.WriteLine("prd.Width = " + prd.Width);
            Console.WriteLine("prd.Height = " + prd.Height);
            Console.WriteLine("band.Width = " + band.Width);
            Console.WriteLine("band.Height= " + band.Height);
            fixed(Int16 *ptr = buffer)
            {
                IntPtr bufferPtr = new IntPtr(ptr);

                band.Read(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.Int16, prd.Width, prd.Height);
            }

            string           dstFname   = @"e:\mvg_writer.bin";
            string           mapInfo    = "{1,1}:{110,35}:{0.01,0.01}";
            Int16            valueCount = 2;
            bool             withHdr    = true;
            string           values     = "{ 0, 1 }";
            string           valueNames = "{120,99}";
            IMvgDataProvider prdWriter  = (drv as IRasterDataDriver).Create(dstFname, prd.Width, prd.Height, 1, enumDataType.Int16, "VALUECOUNT=" + valueCount, "VALUES=" + values,
                                                                            "VALUENAMES=" + valueNames, "MAPINFO=" + mapInfo, "WITHHDR=" + withHdr.ToString()) as IMvgDataProvider;
            IRasterBand bandWriter = prdWriter.GetRasterBand(1);

            fixed(Int16 *ptr = buffer)
            {
                IntPtr bufferPtr = new IntPtr(ptr);

                bandWriter.Write(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.Int16, prd.Width, prd.Height);
            }

            prd.Dispose();
            drv.Dispose();
            prdWriter.Dispose();
        }
        public void MvgToLdfFile()
        {
            _fname = @"E:\气象局项目\MAS二期\mvg文件\FOG_DBLV_FY3A_VIRR_1000M_DXX_P001_200911131354.mvg";
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.NotNull(prd);

            IMvgDataProvider mvgPrd    = prd as IMvgDataProvider;
            MvgHeader        mvgHeader = mvgPrd.Header;

            Assert.NotNull(mvgHeader);
            Console.WriteLine("mvgHeader.HeaderSize = " + mvgHeader.HeaderSize);
            Console.WriteLine("mvgHeader.Width = " + mvgHeader.Width);
            Console.WriteLine("mvgHeader.Height = " + mvgHeader.Height);

            mvgPrd.ToLdfFile();
            mvgPrd.Dispose();
            prd.Dispose();
            drv.Dispose();
        }
Example #7
0
        public unsafe void ReadMvgFile_smaller()
        {
            // _fname = @"C:\工作\3.13\SNW_DBLV_FY3A_VIRR_1000M_NULL_P001_200911131356.mvg";
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.NotNull(prd);
            Int16[] data = new Int16[prd.Width / 2 * prd.Height];
            Console.WriteLine("prd.Width = " + prd.Width);
            Console.WriteLine("prd.Height = " + prd.Height);
            int[] bandMap = { 1 };
            fixed(Int16 *ptr = data)
            {
                IntPtr buffer = new IntPtr(ptr);

                prd.Read(0, 0, prd.Width, prd.Height, buffer, enumDataType.Int16, prd.Width / 2, prd.Height, 1, bandMap, enumInterleave.BSQ);
            }

            string dstFname = @"e:\mvg";//@"C:\工作\3.13\read";

            WriteBandToFile(data, dstFname + "_smaller" + "_prdRead" + ".dat");
        }
Example #8
0
        /// <summary>
        /// ldf文件另存为mvg文件
        /// </summary>
        /// <param name="ldfName">ldf文件名</param>
        /// <param name="mvgName">mvg文件名</param>
        /// <param name="bandNo">需要获取的波段号</param>
        /// <param name="options">

        /*
         *  VALUECOUNT = 2         //default:0
         *  VALUES = "{0,1}"       //
         *  VALUENAMES             //
         *  SPATIALREF=Proj4                  //default:wgs-84
         *  MAPINFO={X,Y}:{Col,Row}:{ResolutionX,ResolutionY} //default:null
         *  WITHHDR=[TRUE|FALSE]      //default:true
         */
        /// </param>
        public static void FromLDF(string ldfFileName, string mvgFileName, int bandNo, params object[] options)
        {
            IGeoDataDriver      ldfDrv  = null;
            IRasterDataProvider ldfPrd  = null;
            IRasterBand         ldfBand = null;
            IMvgDriver          mvgDrv  = null;
            IMvgDataProvider    mvgPrd  = null;
            IRasterBand         mvgBand = null;

            try
            {
                ldfDrv = GeoDataDriver.GetDriverByName("LDF");
                if (ldfDrv == null)
                {
                    return;
                }
                ldfPrd = ldfDrv.Open(ldfFileName, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;
                if (ldfPrd == null)
                {
                    return;
                }
                Ldf1Header ldfHeader = (ldfPrd as ILdfDataProvider).Header as Ldf1Header;
                if (ldfHeader == null || (ldfHeader.DataType != enumDataType.Int16 && ldfHeader.DataType != enumDataType.UInt16))
                {
                    throw new NotSupportedException("只支持Int16和UInt16数据格式的LDF文件转换!");
                }
                ldfBand = ldfPrd.GetRasterBand(bandNo);
                if (ldfBand == null)
                {
                    return;
                }

                //创建MVG文件
                mvgDrv = GeoDataDriver.GetDriverByName("MVG") as IMvgDriver;
                if (mvgDrv == null)
                {
                    return;
                }
                mvgPrd = mvgDrv.Create(mvgFileName, ldfBand.Width, ldfBand.Height, 1, enumDataType.Int16, options) as IMvgDataProvider;
                if (mvgPrd == null)
                {
                    return;
                }
                MvgHeaderConvertor.FillMvgHeader(ldfHeader, mvgPrd.Header);
                //重新生成hdr头文件
                string hdrFileName = HdrFile.GetHdrFileName(mvgFileName);
                HdrFile.SaveTo(hdrFileName, mvgPrd.Header.ToHdrFile());

                //读数据并写入MVG文件中
                mvgBand = mvgPrd.GetRasterBand(1);
                if (mvgBand == null)
                {
                    return;
                }
                WriteDataFromLdfToMvg(ldfHeader, ldfBand, mvgBand);
            }
            finally
            {
                if (mvgPrd != null)
                {
                    (mvgPrd as MvgDataProvider).Disposed(ldfDrv, ldfPrd, ldfBand, mvgDrv, mvgPrd, mvgBand);
                }
            }
        }