コード例 #1
0
 public static void FillMvgHeader(Ldf1Header ldfHeader, MvgHeader mvgHeader)
 {
     mvgHeader.CreatedDateTime     = ldfHeader.YMDHM;
     mvgHeader.ProjectType         = ldfHeader.ProjectType;
     mvgHeader.Width               = (Int16)ldfHeader.Width;
     mvgHeader.Height              = (Int16)ldfHeader.Height;
     mvgHeader.LongitudeResolution = ldfHeader.LonSolution;
     mvgHeader.LatitudeResolution  = ldfHeader.LatSolution;
     mvgHeader.StandardLatitude1   = ldfHeader.StandardLat1;
     mvgHeader.StandardLatitude2   = ldfHeader.StandardLat2;
     mvgHeader.EarthRadius         = ldfHeader.EarthRadius;
     mvgHeader.MinLat              = ldfHeader.MinLat;
     mvgHeader.MaxLat              = ldfHeader.MaxLat;
     mvgHeader.MinLon              = ldfHeader.MinLon;
     mvgHeader.MaxLon              = ldfHeader.MaxLon;
     mvgHeader.IsExtend            = ldfHeader.IsExtended;
     mvgHeader.SpatialRef          = ldfHeader.SpatialRef;
     if (ldfHeader.IsExtended)
     {
         mvgHeader.GeoDoIdentify = ldfHeader.GeoDoIdentify;
         mvgHeader.PrjId         = ldfHeader.PrjId;
         mvgHeader.A             = ldfHeader.A;
         mvgHeader.B             = ldfHeader.B;
         mvgHeader.Sp1           = ldfHeader.Sp1;
         mvgHeader.Sp2           = ldfHeader.Sp2;
         mvgHeader.Lat0          = ldfHeader.Lat0;
         mvgHeader.Lon0          = ldfHeader.Lon0;
         mvgHeader.X0            = ldfHeader.X0;
         mvgHeader.Y0            = ldfHeader.Y0;
         mvgHeader.K0            = ldfHeader.K0;
     }
 }
コード例 #2
0
 private static void GetLdfHeaderSpatialRef(MvgHeader mvgHeader, Ldf1Header ldfHeader)
 {
     if (mvgHeader.Version == 3)
     {
         GetLdfHeaderSpatialRefByExtend(mvgHeader, ldfHeader);
     }
 }
コード例 #3
0
        public static Ldf1Header MvgHeaderToLdfHeader(MvgHeader mvgHeader)
        {
            Ldf1Header ldfHeader = new Ldf1Header();

            FillLdfHeaderAttributes(mvgHeader, ldfHeader);
            return(ldfHeader);
        }
コード例 #4
0
ファイル: MvgDataProvider.cs プロジェクト: configare/hispeed
        private static void WriteDataFromLdfToMvg(Ldf1Header ldfHeader, IRasterBand ldfBand, IRasterBand mvgBand)
        {
            int width       = ldfBand.Width;
            int height      = ldfBand.Height;
            int rowsOfBlock = (int)Math.Floor((float)GeoDo.RSS.Core.DF.Constants.MAX_PIXELS_BLOCK / (width * DataTypeHelper.SizeOf(enumDataType.Int16)));//每块的行数

            if (rowsOfBlock > height)
            {
                rowsOfBlock = height;
            }
            int countBlocks = (int)Math.Floor((float)height / rowsOfBlock); //总块数

            Int16[] buffer    = new Int16[rowsOfBlock * width];
            IntPtr  bufferPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);

            int bRow           = 0;
            int eRow           = 0;
            int bufferRowCount = 0;

            for (int i = 0; i < countBlocks; i++, bRow += rowsOfBlock)
            {
                eRow           = Math.Min(height, bRow + rowsOfBlock);
                bufferRowCount = eRow - bRow;
                ldfBand.Read(0, bRow, width, bufferRowCount, bufferPtr, ldfHeader.DataType, width, bufferRowCount);
                mvgBand.Write(0, bRow, width, bufferRowCount, bufferPtr, enumDataType.Int16, width, bufferRowCount);
            }
        }
コード例 #5
0
ファイル: LdfDriver_Create.cs プロジェクト: configare/hispeed
        public void CreateEmptyLdfFile()
        {
            Assert.That(_newFileName != null);
            IGeoDataDriver driver = GeoDataDriver.GetDriverByName("LDF");

            Assert.NotNull(driver);
            ILdfDriver drv = driver as ILdfDriver;

            Assert.NotNull(drv);
            int            width      = 2048;
            int            height     = 3390;
            int            bandCount  = 10;
            enumDataType   dataType   = enumDataType.UInt16;
            enumInterleave interleave = enumInterleave.BSQ;
            string         version    = "LDF";
            //string proj4 = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137";
            string           mapInfo = "{1,1}:{110,35}:{0.01,0.01}";
            bool             withHdr = true;
            ILdfDataProvider prd     = drv.Create(_newFileName, width, height, bandCount, dataType,
                                                  "INTERLEAVE=" + interleave.ToString(),
                                                  "VERSION=" + version,
                                                  //"SPATIALREF=" + proj4,
                                                  "MAPINFO=" + mapInfo, "WITHHDR=" + withHdr.ToString()) as ILdfDataProvider;

            Assert.NotNull(prd);
            Assert.That(prd.Width == width && prd.Height == height);
            Assert.That(prd.BandCount == bandCount);
            Assert.That(prd.DataType == dataType);
            ILdfHeader header = prd.Header;

            Assert.NotNull(header);
            HdrFile hdr = header.ToHdrFile();

            PrintHdrInfo(hdr);
            Ldf1Header ldfheader = header as Ldf1Header;

            Assert.NotNull(ldfheader);
            Assert.That(ldfheader._width == width && ldfheader._height == height);
            Assert.That(ldfheader.DataType == dataType);
            Assert.NotNull(prd.SpatialRef);
            for (int i = 0; i < bandCount; i++)
            {
                IRasterBand band = prd.GetRasterBand(i + 1);
                Assert.NotNull(band);
                Assert.That(band.Width == width && band.Height == height);
                Assert.That(band.DataType == dataType);
            }
            prd.Dispose();
            drv.Dispose();
            Assert.True(File.Exists(_newFileName));
            FileInfo fInfo = new FileInfo(_newFileName);

            Assert.True(width * height * bandCount * 2 + header.HeaderSize == fInfo.Length);
            ISpatialReference spatialRef = prd.SpatialRef;

            Assert.NotNull(spatialRef);
            Console.Out.WriteLine(spatialRef.ToString());
        }
コード例 #6
0
 private static void GetLdfHeaderSpatialRefByExtend(MvgHeader mvgHeader, Ldf1Header ldfHeader)
 {
     ldfHeader.GeoDoIdentify = mvgHeader.GeoDoIdentify;
     ldfHeader.PrjId         = mvgHeader.PrjId;
     ldfHeader.A             = mvgHeader.A;
     ldfHeader.B             = mvgHeader.B;
     ldfHeader.Sp1           = mvgHeader.Sp1;
     ldfHeader.Sp2           = mvgHeader.Sp2;
     ldfHeader.Lat0          = mvgHeader.Lat0;
     ldfHeader.Lon0          = mvgHeader.Lon0;
     ldfHeader.X0            = mvgHeader.X0;
     ldfHeader.Y0            = mvgHeader.Y0;
     ldfHeader.K0            = mvgHeader.K0;
 }
コード例 #7
0
ファイル: MvgDataProvider.cs プロジェクト: configare/hispeed
        public void ToLdfFile(string ldfFileName)
        {
            ILdfDriver          ldfDrv    = null;
            IRasterDataProvider ldfPrd    = null;
            IRasterBand         ldfBand   = null;
            IRasterBand         mvgBand   = null;
            Ldf1Header          ldfHeader = null;

            try
            {
                ldfDrv = GeoDataDriver.GetDriverByName("LDF") as ILdfDriver;
                if (ldfDrv == null)
                {
                    return;
                }
                ldfPrd = ldfDrv.Create(ldfFileName, _width, _height, 1, enumDataType.Int16);
                if (ldfPrd == null)
                {
                    return;
                }
                ldfBand = ldfPrd.GetRasterBand(1);
                if (ldfBand == null)
                {
                    return;
                }

                ldfHeader = MvgHeaderConvertor.MvgHeaderToLdfHeader(_header);
                if (ldfHeader == null)
                {
                    return;
                }

                //read data by block ,write ldf provider
                mvgBand = GetRasterBand(1);
                if (mvgBand == null)
                {
                    return;
                }
                WriteDataFromMvgToLdf(ldfBand, mvgBand);
            }
            finally
            {
                Disposed(ldfDrv, ldfPrd, ldfBand, null, null, mvgBand);
            }
        }
コード例 #8
0
 private static void FillLdfHeaderAttributes(MvgHeader mvgHeader, Ldf1Header ldfHeader)
 {
     //ldfHeaderBase 成员
     ldfHeader._channelCount = 1;
     ldfHeader._dataType     = (Int16)LdfHeaderBase.DataTypeToIntValue(typeof(Int16));
     ldfHeader._width        = (UInt16)mvgHeader.Width;
     ldfHeader._height       = (UInt16)mvgHeader.Height;
     ldfHeader._headerSize   = 128;
     ldfHeader._interleave   = (Int16)LdfHeaderBase.InterleaveToInt(enumInterleave.BSQ);
     //ldf1Header成员
     ldfHeader.FileIdentify = "LA";
     ldfHeader.YMDHM        = mvgHeader.CreatedDateTime;
     ldfHeader.ProjectType  = mvgHeader.ProjectType;
     ldfHeader.LonSolution  = mvgHeader.LongitudeResolution;
     ldfHeader.LatSolution  = mvgHeader.LatitudeResolution;
     ldfHeader.StandardLat1 = mvgHeader.StandardLatitude1;
     ldfHeader.StandardLat2 = mvgHeader.StandardLatitude2;
     ldfHeader.EarthRadius  = mvgHeader.EarthRadius;
     ldfHeader.MinLat       = mvgHeader.MinLat;
     ldfHeader.MaxLat       = mvgHeader.MaxLat;
     ldfHeader.MinLon       = mvgHeader.MinLon;
     ldfHeader.MaxLon       = mvgHeader.MaxLon;
     GetLdfHeaderSpatialRef(mvgHeader, ldfHeader);
 }
コード例 #9
0
ファイル: Process.cs プロジェクト: windygu/hispeed
        public void Mosaic(string[] rasterFiles, string outrasterFile, GeoHeader geoHeader, Action <int, string> progress)
        {
            using (IRasterDataProvider outraster = CreateMosaicRaster(outrasterFile, geoHeader))
            {
                string filename                       = null;
                IRasterDataProvider raster            = null;
                string solarZenithFilename            = null;
                IRasterDataProvider solarZenithRaster = null;

                RasterMaper         rmOutSolarZenith    = null;// new RasterMaper(solarZenithRaster, new int[] { 1 });
                string              outSolarZenithFile  = Path.ChangeExtension(outrasterFile, ".SolarZenith.ldf");
                IRasterDataProvider outSolarZenithRster = null;
                try
                {
                    for (int f = 0; f < rasterFiles.Length; f++)
                    {
                        filename            = rasterFiles[f];
                        solarZenithFilename = Path.ChangeExtension(filename, ".SolarZenith.ldf");
                        if (progress != null)
                        {
                            progress((int)(f * 100f / rasterFiles.Length), string.Format("{0}/{1}", f + 1, rasterFiles.Length));
                        }
                        try
                        {
                            raster = GeoDataDriver.Open(filename) as IRasterDataProvider;
                            if (raster == null)
                            {
                                continue;
                            }
                            if (raster is ILdfDataProvider)
                            {
                                Ldf1Header header = (raster as ILdfDataProvider).Header as Ldf1Header;
                                if (!header.IsDay)
                                {
                                    Console.WriteLine("跳过晚上数据" + Path.GetFileName(filename));
                                    continue;
                                }
                            }

                            if (File.Exists(outSolarZenithFile))
                            {
                                outSolarZenithRster = GeoDataDriver.Open(outSolarZenithFile, enumDataProviderAccess.Update, null) as IRasterDataProvider;
                                rmOutSolarZenith    = new RasterMaper(outSolarZenithRster, new int[] { 1 });
                            }

                            RasterMaper rmSz = null;
                            if (File.Exists(solarZenithFilename))
                            {
                                solarZenithRaster = GeoDataDriver.Open(solarZenithFilename) as IRasterDataProvider;
                                rmSz = new RasterMaper(solarZenithRaster, new int[] { 1 });
                            }
                            RasterMaper rmin  = new RasterMaper(raster, new int[] { 1, 2, 3 });
                            RasterMaper rmout = new RasterMaper(outraster, new int[] { 1, 2, 3 });
                            RasterProcessModel <short, short> rp = new RasterProcessModel <short, short>();
                            RasterMaper[] rmIns, rmOuts;
                            if (rmSz != null)
                            {
                                rmIns = new RasterMaper[] { rmin, rmSz }
                            }
                            ;
                            else
                            {
                                rmIns = new RasterMaper[] { rmin }
                            };
                            if (rmOutSolarZenith != null)
                            {
                                rmOuts = new RasterMaper[] { rmout, rmOutSolarZenith }
                            }
                            ;
                            else
                            {
                                rmOuts = new RasterMaper[] { rmout }
                            };

                            rp.SetRaster(rmIns, rmOuts);
                            rp.RegisterCalcModel(new RasterCalcHandlerFun <short, short>((rasterVistor, target, map) =>
                            {
                                if (rasterVistor[0] == null || rasterVistor[0].RasterBandsData.Length == 0)
                                {
                                    return(false);
                                }
                                if (target[0] == null || target[0].RasterBandsData[0].Length == 0)
                                {
                                    return(false);
                                }
                                bool isUpdate = false;
                                for (int i = 0; i < target[0].RasterBandsData[0].Length; i++)
                                {
                                    if (rasterVistor[0].RasterBandsData[0] == null)
                                    {
                                        continue;
                                    }
                                    if (rasterVistor[0].RasterBandsData[0][i] == 0)
                                    {
                                        continue;
                                    }
                                    //高度角判断白天晚上(高度角=90- 天顶角),高度角为0度时候为直射
                                    if (rasterVistor.Length == 1 || rasterVistor[1] == null || rasterVistor[1].RasterBandsData[0] == null ||
                                        target.Length == 1 || target[1] == null ||
                                        rasterVistor[1].RasterBandsData[0][i] < 0 || rasterVistor[1].RasterBandsData[0][i] > 9000) //白天
                                    {
                                        if (target[0].RasterBandsData[0][i] == 0)                                                  //如果没有角度数据,则采取补数据的方式(即不覆盖已有数据)
                                        {
                                            isUpdate = true;
                                            target[0].RasterBandsData[0][i] = rasterVistor[0].RasterBandsData[0][i];
                                            target[0].RasterBandsData[1][i] = rasterVistor[0].RasterBandsData[1][i];
                                            target[0].RasterBandsData[2][i] = rasterVistor[0].RasterBandsData[2][i];
                                        }
                                    }
                                    else if (target[1].RasterBandsData[0][i] == 0)
                                    {
                                        isUpdate = true;
                                        target[0].RasterBandsData[0][i] = rasterVistor[0].RasterBandsData[0][i];
                                        target[0].RasterBandsData[1][i] = rasterVistor[0].RasterBandsData[1][i];
                                        target[0].RasterBandsData[2][i] = rasterVistor[0].RasterBandsData[2][i];
                                        //更新目标高度角数据
                                        target[1].RasterBandsData[0][i] = rasterVistor[1].RasterBandsData[0][i];
                                    }
                                    else if (rasterVistor[1].RasterBandsData[0][i] < target[1].RasterBandsData[0][i])
                                    {
                                        isUpdate = true;
                                        target[0].RasterBandsData[0][i] = rasterVistor[0].RasterBandsData[0][i];
                                        target[0].RasterBandsData[1][i] = rasterVistor[0].RasterBandsData[1][i];
                                        target[0].RasterBandsData[2][i] = rasterVistor[0].RasterBandsData[2][i];
                                        //更新目标高度角数据
                                        target[1].RasterBandsData[0][i] = rasterVistor[1].RasterBandsData[0][i];
                                    }
                                }
                                if (isUpdate)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                                                                                         ));
                            rp.Excute();
                        }
                        finally
                        {
                            if (raster != null)
                            {
                                raster.Dispose();
                                raster = null;
                            }
                            if (outSolarZenithRster != null)
                            {
                                outSolarZenithRster.Dispose();
                                outSolarZenithRster = null;
                            }
                        }
                    }
                }
                finally
                {
                    if (outSolarZenithRster != null)
                    {
                        outSolarZenithRster.Dispose();
                        outSolarZenithRster = null;
                    }
                }
            }
        }
コード例 #10
0
ファイル: MvgDataProvider.cs プロジェクト: configare/hispeed
        /// <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);
                }
            }
        }