private Band[] TryCreateRasterDataBands(AbstractWarpDataset srcRaster, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback)
        {
            List <Band> rasterBands = new List <Band>();

            if (prjSettings.OutBandNos == null)
            {
                int count = srcRaster.BandCount;

                for (int i = 0; i < count; i++)
                {
                    if (progressCallback != null)
                    {
                        progressCallback(_readyProgress++, "准备第" + i + "个输入数据通道");
                    }
                    Band band = srcRaster.GetRasterBand(i);
                    rasterBands.Add(band);
                }
            }
            else
            {
                foreach (var i in prjSettings.OutBandNos)
                {
                    Band band = srcRaster.GetRasterBand(i);
                    rasterBands.Add(band);
                }
            }

            return(rasterBands.ToArray());
        }
 private void TryCreateDefaultArg(AbstractWarpDataset srcRaster, FY3L2L3FilePrjSettings prjSettings, ref SpatialReference dstSpatialRef)
 {
     if (dstSpatialRef == null)
     {
         dstSpatialRef = _srcSpatialRef;
     }
     if (string.IsNullOrWhiteSpace(prjSettings.OutFormat))
     {
         prjSettings.OutFormat = "LDF";
     }
     if (dstSpatialRef.IsGeographic() == 1)
     {
         _srcImgResolution = 0.01f;
     }
     else
     {
         _srcImgResolution = 0.01f;
     }
     if (prjSettings.OutResolutionX == 0 || prjSettings.OutResolutionY == 0)
     {
         if (dstSpatialRef.IsGeographic() == 1)
         {
             prjSettings.OutResolutionX = 0.01f;
             prjSettings.OutResolutionY = 0.01f;
         }
         else
         {
             prjSettings.OutResolutionX = 1000f;
             prjSettings.OutResolutionY = 1000f;
         }
     }
 }
        private FY3L2L3FilePrjSettings ArgsCheck(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback)
        {
            if (srcRaster == null)
            {
                throw new ArgumentNullException("srcRaster", "待投影数据为空");
            }
            if (prjSettings == null)
            {
                throw new ArgumentNullException("prjSettings", "投影参数为空");
            }
            FY3L2L3FilePrjSettings _prjSettings = prjSettings as FY3L2L3FilePrjSettings;

            if (_prjSettings.LocationFile == null)
            {
                throw new ArgumentNullException("prjSettings.LocationFile", "L2L3级轨道数据投影未设置经纬度数据集文件");
            }
            return(_prjSettings);
        }
 private void DoSession(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession == null || _curSession != srcRaster || _isBeginSession)
     {
         AbstractWarpDataset locationRester = prjSettings.LocationFile;
         ReadyLocations(locationRester, dstSpatialRef, out _xs, out _ys, out _maxPrjEnvelope, out _srcLocationSize, progressCallback);
         if (_srcLocationSize.Width != srcRaster.Width || _srcLocationSize.Height != srcRaster.Height)
         {
             throw new ArgumentException("输入经纬度查找表长宽参数异常");
         }
         if (progressCallback != null)
         {
             progressCallback(_readyProgress++, "准备其他参数");
         }
         //if (prjSettings.IsSolarZenith && prjSettings.IsRadiation)
         //{
         //    _szDataFilename = GetSolarZenithCacheFilename(locationRester.fileName);
         //    if (!File.Exists(_szDataFilename))
         //        ReadySolarZenithArgsToFile(locationRester);
         //    else
         //        _solarZenithCacheRaster = GeoDataDriver.Open(_szDataFilename) as AbstractWarpDataset;
         //    if (prjSettings.IsSensorZenith)
         //    {
         //        ReadySensorZenith(locationRester);
         //    }
         //}
         _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback);
         _isBeginSession  = false;
     }
 }
 private void SetPrjBand(FY3L2L3FilePrjSettings prjSettings, PrjBand[] defaultPrjBands)
 {
 }
        private void ReadyArgs(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings, SpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            float resolutionScale = 1f;

            _readyProgress = 0;
            if (progressCallback != null)
            {
                progressCallback(_readyProgress++, "准备相关参数");
            }
            if (dstSpatialRef == null)
            {
                dstSpatialRef = SpatialReferenceFactory.CreateSpatialReference(4326);
            }
            _dstSpatialRef = dstSpatialRef;
            _prjSettings   = ArgsCheck(srcRaster, prjSettings, progressCallback);
            //_fileType = CheckFile(srcRaster);
            _locationRaster = (prjSettings as FY3L2L3FilePrjSettings).LocationFile;
            ReadExtArgs(prjSettings);
            TryCreateDefaultArg(srcRaster, _prjSettings, ref _dstSpatialRef);
            _left  = 0;
            _right = 0;
            TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs);
            DoSession(srcRaster, _dstSpatialRef, _prjSettings, progressCallback);
            if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty)
            {
                _prjSettings.OutEnvelope = _maxPrjEnvelope;
                _orbitBlock = new Block {
                    xBegin = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1
                };
            }
            else
            {
                GetEnvelope(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, _prjSettings.OutEnvelope, out _orbitBlock);
                if (_orbitBlock == null || _orbitBlock.Width <= 0 || _orbitBlock.Height <= 0)
                {
                    throw new Exception("数据不在目标区间内");
                }
                float invalidPresent = (_orbitBlock.Width * _orbitBlock.Height * resolutionScale) / (srcRaster.Width * srcRaster.Height);
                if (invalidPresent < 0.0001f)
                {
                    throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%");
                }
                if (invalidPresent > 0.60f)
                {
                    _orbitBlock = new Block {
                        xBegin = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1
                    }
                }
                ;
            }
            _dstEnvelope = _prjSettings.OutEnvelope;
            if (!_dstEnvelope.IntersectsWith(_maxPrjEnvelope))
            {
                throw new Exception("数据不在目标区间内");
            }
            _outResolutionX = _prjSettings.OutResolutionX;
            _outResolutionY = _prjSettings.OutResolutionY;
            _outFormat      = _prjSettings.OutFormat;
            _outfilename    = _prjSettings.OutPathAndFileName;
            _dstProj4       = _dstSpatialRef.ExportToProj4();
            _dstBandCount   = _rasterDataBands.Length;
            //_dstBandCount = _rasterDataBands.Length;
            _dstSize = _prjSettings.OutSize;
            //_isRadiation = _prjSettings.IsRadiation;
            //_isSolarZenith = _prjSettings.IsSolarZenith;
            //_isSensorZenith = _prjSettings.IsSensorZenith;
        }