Ejemplo n.º 1
0
        //621
        private string PrjVIRR(IRasterDataProvider srcRaster, ISpatialReference projRef)
        {
            List <BandMap> bandmapList = new List <BandMap>();

            bandmapList.Add(new BandMap()
            {
                DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 0
            });
            bandmapList.Add(new BandMap()
            {
                DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 1
            });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_Emissive", File = srcRaster, BandIndex = 0 });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_Emissive", File = srcRaster, BandIndex = 1 });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_Emissive", File = srcRaster, BandIndex = 2 });
            bandmapList.Add(new BandMap()
            {
                DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 2
            });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 3 });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 4 });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 5 });
            //bandmapList.Add(new BandMap() { DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 6 });

            IFileProjector       projTor    = FileProjector.GetFileProjectByName("FY3_VIRR");
            FY3_VIRR_PrjSettings prjSetting = new FY3_VIRR_PrjSettings();

            prjSetting.OutPathAndFileName = GetOutPutFile(srcRaster.fileName, projRef);
            prjSetting.BandMapTable       = bandmapList;

            ISpatialReference dstSpatialRef = projRef;

            projTor.Project(srcRaster, prjSetting, dstSpatialRef, _progress);
            return(prjSetting.OutPathAndFileName);
        }
Ejemplo n.º 2
0
        public override void Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            if (srcRaster == null)
            {
                throw new ArgumentNullException("srcRaster");
            }
            if (prjSettings == null)
            {
                throw new ArgumentNullException("prjSettings");
            }
            FY3_VIRR_PrjSettings fy3prjSettings = prjSettings as FY3_VIRR_PrjSettings;

            TryCreateDefaultArgs(srcRaster, fy3prjSettings, ref dstSpatialRef);
            DoSession(srcRaster, dstSpatialRef, fy3prjSettings, progressCallback);
            if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty)
            {
                prjSettings.OutEnvelope = _maxPrjEnvelope;
            }
            //地理坐标投影,下面简单的对地理坐标投影的范围作了限制,不大严谨,仅适合目前的状况。
            if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80))
            {
                throw new Exception(string.Format("高纬度数据,不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope));
            }
            Project(srcRaster, fy3prjSettings, dstSpatialRef, progressCallback);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 0、先生成目标文件,以防止目标空间不足。
        /// 1、计算查找表
        /// 2、对所有波段执行投影
        /// </summary>
        private void ProjectToLDF(IRasterDataProvider srcRaster, FY3_VIRR_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            string         outFormat    = prjSettings.OutFormat;
            string         outfilename  = prjSettings.OutPathAndFileName;
            string         dstProj4     = dstSpatialRef.ToProj4String();
            List <BandMap> bandMaps     = prjSettings.BandMapTable;
            int            dstBandCount = bandMaps.Count;
            Size           srcSize      = new Size(srcRaster.Width, srcRaster.Height);
            Size           dstSize      = prjSettings.OutSize;

            using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver)
            {
                PrjEnvelope dstEnvelope = prjSettings.OutEnvelope;
                string      mapInfo     = "MAPINFO={" + 1 + "," + 1 + "}:{" + dstEnvelope.MinX + "," + dstEnvelope.MaxY + "}:{" + prjSettings.OutResolutionX + "," + prjSettings.OutResolutionY + "}";
                using (IRasterDataProvider prdWriter = drv.Create(outfilename, dstSize.Width, dstSize.Height, dstBandCount,
                                                                  enumDataType.UInt16, "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + dstProj4, mapInfo, "WITHHDR=TRUE") as IRasterDataProvider)
                {
                    //计算查找表
                    //ISpatialReference srcSpatialRef = srcRaster.SpatialRef;
                    UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    _rasterProjector.ComputeIndexMapTable(_xs, _ys, srcSize, dstSize, dstEnvelope, _maxPrjEnvelope,
                                                          out dstRowLookUpTable, out dstColLookUpTable, progressCallback);
                    //执行投影
                    UInt16[] srcBandData = new UInt16[srcSize.Width * srcSize.Height];
                    UInt16[] dstBandData = new UInt16[dstSize.Width * dstSize.Height];
                    int      progress    = 0;
                    for (int i = 0; i < dstBandCount; i++)      //读取原始通道值,投影到目标区域
                    {
                        if (progressCallback != null)
                        {
                            progress = (int)((i + 1) * 100 / dstBandCount);
                            progressCallback(progress, string.Format("投影第{0}共{1}通道", i + 1, dstBandCount));
                        }
                        BandMap bandMap = bandMaps[i];
                        ReadBandData(srcBandData, bandMap.File, bandMap.DatasetName, bandMap.BandIndex, srcSize);
                        if (prjSettings.IsRadiation)
                        {
                            DoRadiation(srcBandData, srcSize, bandMap.DatasetName, bandMap.BandIndex, prjSettings.IsSolarZenith);
                        }
                        _rasterProjector.Project <UInt16>(srcBandData, srcSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstBandData, 0, progressCallback);
                        using (IRasterBand band = prdWriter.GetRasterBand(i + 1))
                        {
                            unsafe
                            {
                                fixed(UInt16 *ptr = dstBandData)
                                {
                                    IntPtr bufferPtr = new IntPtr(ptr);

                                    band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.UInt16, band.Width, band.Height);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void TryCreateDefaultArgs(IRasterDataProvider srcRaster, FY3_VIRR_PrjSettings prjSettings, ref ISpatialReference dstSpatialRef)
 {
     if (dstSpatialRef == null)
     {
         dstSpatialRef = _srcSpatialRef;
     }
     if (string.IsNullOrWhiteSpace(prjSettings.OutFormat))
     {
         prjSettings.OutFormat = "LDF";
     }
     if (dstSpatialRef.ProjectionCoordSystem == null)
     {
         _srcImgResolution = 0.01F;
     }
     else
     {
         _srcImgResolution = 1000f;
     }
     if (prjSettings.OutResolutionX <= 0 || prjSettings.OutResolutionY <= 0)
     {
         if (dstSpatialRef.ProjectionCoordSystem == null)
         {
             prjSettings.OutResolutionX = 0.01F;
             prjSettings.OutResolutionY = 0.01F;
         }
         else
         {
             prjSettings.OutResolutionX = 1000F;
             prjSettings.OutResolutionY = 1000F;
         }
     }
     if (prjSettings.OutBandNos == null || prjSettings.OutBandNos.Length == 0)
     {
         _prjBands = PrjBand.VIRR_1000_Orbit;
     }
     else
     {
         List <PrjBand> bands    = new List <PrjBand>();
         PrjBand[]      defbands = PrjBand.VIRR_1000_Orbit;
         foreach (int bandNo in prjSettings.OutBandNos)
         {
             bands.Add(defbands[bandNo - 1]);
         }
         _prjBands = bands.ToArray();
     }
 }
Ejemplo n.º 5
0
        private void Project(IRasterDataProvider srcRaster, FY3_VIRR_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            PrjEnvelope envelops = prjSettings.OutEnvelope;

            if (envelops.IntersectsWith(_maxPrjEnvelope))
            {
                switch (prjSettings.OutFormat)
                {
                case "LDF":
                    ProjectToLDF(srcRaster, prjSettings, dstSpatialRef, progressCallback);
                    break;

                case "MEMORY":
                default:
                    throw new NotSupportedException(string.Format("暂不支持的输出格式", prjSettings.OutFormat));
                }
            }
            else
            {
                throw new Exception("数据不在目标区间内");
            }
        }
Ejemplo n.º 6
0
        public override IRasterDataProvider Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, IRasterDataProvider dstRaster, int beginBandIndex, Action <int, string> progressCallback)
        {
            if (srcRaster == null)
            {
                throw new ArgumentNullException("srcRaster");
            }
            if (prjSettings == null)
            {
                throw new ArgumentNullException("prjSettings");
            }
            if (dstRaster == null && prjSettings.OutPathAndFileName == null)
            {
                throw new ArgumentNullException("dstRaster");
            }
            try
            {
                FY3_VIRR_PrjSettings fy3prjSettings = prjSettings as FY3_VIRR_PrjSettings;
                ISpatialReference    dstSpatialRef  = dstRaster.SpatialRef;
                TryCreateDefaultArgs(srcRaster, fy3prjSettings, ref dstSpatialRef);
                DoSession(srcRaster, _geoDataProvider, dstSpatialRef, fy3prjSettings, progressCallback);
                if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty)
                {
                    prjSettings.OutEnvelope = _maxPrjEnvelope;
                }
                if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80))
                {
                    throw new Exception(string.Format("高纬度数据[>80],不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope));
                }
                if (dstRaster == null)
                {
                    PrjEnvelope       dstEnvelope  = prjSettings.OutEnvelope;
                    string            outFormat    = prjSettings.OutFormat;
                    string            outfilename  = prjSettings.OutPathAndFileName;
                    string            dstProj4     = dstSpatialRef.ToProj4String();
                    int               dstBandCount = _prjBands.Length;
                    Size              srcSize      = new Size(srcRaster.Width, srcRaster.Height);
                    Size              dstSize      = prjSettings.OutSize;
                    IRasterDataDriver drv          = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

                    string[] options = new string[] {
                        "INTERLEAVE=BSQ",
                        "VERSION=LDF",
                        "WITHHDR=TRUE",
                        "SPATIALREF=" + dstProj4,
                        "MAPINFO={" + 1 + "," + 1 + "}:{" + dstEnvelope.MinX + "," + dstEnvelope.MaxY + "}:{" + prjSettings.OutResolutionX + "," + prjSettings.OutResolutionY + "}"
                    };
                    dstRaster = drv.Create(outfilename, dstSize.Width, dstSize.Height, dstBandCount, enumDataType.UInt16, options) as IRasterDataProvider;
                }
                ProjectToLDF(srcRaster, dstRaster, 0, progressCallback);
                return(dstRaster);
            }
            catch
            {
                EndSession();
                TryDeleteCurCatch();
                throw;
            }
            finally
            {
                EndSession();
                if (prjSettings.IsClearPrjCache)
                {
                    TryDeleteCurCatch();
                }
            }
        }
Ejemplo n.º 7
0
        private IRasterBand[] TryCreateRasterDataBands(IRasterDataProvider srcRaster, FY3_VIRR_PrjSettings prjSettings, Action <int, string> progressCallback)
        {
            IBandProvider      srcbandpro  = srcRaster.BandProvider as IBandProvider;
            List <IRasterBand> rasterBands = new List <IRasterBand>();

            for (int i = 0; i < _prjBands.Length; i++)
            {
                if (progressCallback != null)
                {
                    progressCallback(_readyProgress++, "准备第" + i + "个输入数据通道");
                }
                PrjBand       bandMap  = _prjBands[i];
                IRasterBand[] latBands = srcbandpro.GetBands(bandMap.DataSetName);
                IRasterBand   band     = latBands[bandMap.DataSetIndex];
                rasterBands.Add(band);
            }
            return(rasterBands.ToArray());
        }
Ejemplo n.º 8
0
 private void DoSession(IRasterDataProvider srcRaster, IRasterDataProvider geoRaster, ISpatialReference dstSpatialRef, FY3_VIRR_PrjSettings prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession == null || _curSession != srcRaster || _isBeginSession)
     {
         if (progressCallback != null)
         {
             progressCallback(_readyProgress++, "读取及预处理经纬度数据集");
         }
         ReadyLocations(_geoDataProvider, SpatialReference.GetDefault(), dstSpatialRef, out _srcLocationSize, out _xs, out _ys, out _maxPrjEnvelope, progressCallback);
         if (progressCallback != null)
         {
             progressCallback(_readyProgress++, "准备其他参数");
         }
         if (prjSettings.IsRadiation)
         {
             ReadyRadiationArgs(srcRaster);
         }
         if (prjSettings.IsSolarZenith && prjSettings.IsRadiation)
         {
             _solarZenithCacheFilename = GetSolarZenithCacheFilename(geoRaster.fileName);    //太阳天顶角数据
             if (!File.Exists(_solarZenithCacheFilename))
             {
                 ReadySolarZenithArgsToFile(geoRaster);
             }
             else
             {
                 _solarZenithCacheRaster = GeoDataDriver.Open(_solarZenithCacheFilename) as IRasterDataProvider;
             }
             if (prjSettings.IsSensorZenith)
             {
                 ReadySensorZenith(geoRaster);
             }
         }
         _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback);
         _isBeginSession  = false;
     }
 }
Ejemplo n.º 9
0
        private void ReadyArgs(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            if (srcRaster == null)
            {
                throw new ArgumentNullException("srcRaster");
            }
            if (prjSettings == null)
            {
                throw new ArgumentNullException("prjSettings");
            }
            _readyProgress   = 0;
            _prjSettings     = prjSettings as FY3_VIRR_PrjSettings;
            _geoDataProvider = (prjSettings as FY3_VIRR_PrjSettings).GeoFile;
            _dstSpatialRef   = dstSpatialRef;
            MemoryHelper.MemoryNeed(200, 1536);//剩余200MB,已使用1.2GB
            if (progressCallback != null)
            {
                progressCallback(_readyProgress++, "准备相关参数");
            }

            TryCreateDefaultArgs(srcRaster, _prjSettings, ref dstSpatialRef);
            //这里去除的是读取轨道数据时候的左右像元个数。
            _left  = 8;
            _right = 8;
            TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs);
            DoSession(srcRaster, _geoDataProvider, dstSpatialRef, _prjSettings, progressCallback);
            if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty)
            {
                prjSettings.OutEnvelope = _maxPrjEnvelope;
                _orbitBlock             = new Block {
                    xOffset = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1
                };
            }
            else
            {
                GetEnvelope(_xs, _ys, srcRaster.Width, srcRaster.Height, _prjSettings.OutEnvelope, out _orbitBlock);
                if (_orbitBlock == null || _orbitBlock.Width <= 0 || _orbitBlock.Height <= 0)
                {
                    throw new Exception("数据不在目标区间内");
                }
                float invalidPresent = (_orbitBlock.Width * _orbitBlock.Height * 1.0F) / (srcRaster.Width * srcRaster.Height);
                if (invalidPresent < 0.0001f)
                {
                    throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%");
                }
                if (invalidPresent > 0.60)
                {
                    _orbitBlock = new Block {
                        xOffset = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1
                    }
                }
                ;
            }
            //if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80))
            //    throw new Exception(string.Format("高纬度数据,不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope));
            _dstSpatialRef = dstSpatialRef;
            _dstEnvelope   = _prjSettings.OutEnvelope;
            if (!_dstEnvelope.IntersectsWith(_maxPrjEnvelope))
            {
                throw new Exception("数据不在目标区间内");
            }
            _outResolutionX = _prjSettings.OutResolutionX;
            _outResolutionY = _prjSettings.OutResolutionY;
            _outFormat      = _prjSettings.OutFormat;
            _outfilename    = _prjSettings.OutPathAndFileName;
            _dstProj4       = _dstSpatialRef.ToProj4String();
            _dstBandCount   = _prjBands.Length;
            _dstSize        = _prjSettings.OutSize;
            _isRadiation    = _prjSettings.IsRadiation;
            _isSolarZenith  = _prjSettings.IsSolarZenith;
            _isSensorZenith = _prjSettings.IsSensorZenith;
        }
Ejemplo n.º 10
0
 private void TryCreateDefaultArgs(IRasterDataProvider srcRaster, FY3_VIRR_PrjSettings prjSettings, ref ISpatialReference dstSpatialRef)
 {
     if (dstSpatialRef == null)
     {
         dstSpatialRef = _srcSpatialRef;
     }
     if (string.IsNullOrWhiteSpace(prjSettings.OutFormat))
     {
         prjSettings.OutFormat = "LDF";
     }
     if (prjSettings.OutResolutionX == 0 || prjSettings.OutResolutionY == 0)
     {
         if (dstSpatialRef.ProjectionCoordSystem == null)
         {
             prjSettings.OutResolutionX = 0.01F;
             prjSettings.OutResolutionY = 0.01F;
         }
         else
         {
             prjSettings.OutResolutionX = 1000F;
             prjSettings.OutResolutionY = 1000F;
         }
     }
     if (prjSettings.BandMapTable == null || prjSettings.BandMapTable.Count == 0)
     {
         List <BandMap> bandmapList = new List <BandMap>();
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 0
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 1
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_Emissive", File = srcRaster, BandIndex = 0
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_Emissive", File = srcRaster, BandIndex = 1
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_Emissive", File = srcRaster, BandIndex = 2
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 2
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 3
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 4
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 5
         });
         bandmapList.Add(new BandMap()
         {
             DatasetName = "EV_RefSB", File = srcRaster, BandIndex = 6
         });
         prjSettings.BandMapTable = bandmapList;
     }
 }
Ejemplo n.º 11
0
 private void DoSession(IRasterDataProvider srcRaster, ISpatialReference dstSpatialRef, FY3_VIRR_PrjSettings fy3prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession != null && _curSession != srcRaster)
     {
         EndSession();
     }
     if (_curSession == null)
     {
         Size srcSize = new Size(srcRaster.Width, srcRaster.Height);
         ReadyLocations(srcRaster, dstSpatialRef, srcSize, out _xs, out _ys, out _maxPrjEnvelope, progressCallback);
         if (fy3prjSettings.IsRadiation)
         {
             ReadyRadiationArgs(srcRaster);
         }
         if (fy3prjSettings.IsSolarZenith)
         {
             ReadySolarZenithArgs(srcRaster);
         }
     }
 }