예제 #1
0
        public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef,
                                                out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
        {
            InitLocationArgs(srcRaster);
            var projTrans = ProjectionTransformFactory.GetProjectionTransform(_srcSpatialRef, dstSpatialRef);

            float srcResolutionX = Convert.ToSingle(_srcGeoTrans[1]);
            float srcResolutionY = Math.Abs(Convert.ToSingle(_srcGeoTrans[5]));

            double srcLeftTopX = _srcGeoTrans[0];
            double srcLeftTopY = _srcGeoTrans[3];
            int    srcWidth    = srcRaster.Width;
            int    srcHeight   = srcRaster.Height;
            Size   srcSize     = new Size(srcWidth, srcHeight);

            int wSample = 1;
            int hSample = 1;

            if (srcWidth > 1000)
            {
                wSample = srcWidth / 1000;
            }

            if (srcHeight > 1000)
            {
                hSample = srcHeight / 1000;
            }

            double[] xs    = new double[(srcWidth / wSample) * (srcHeight / hSample)];
            double[] ys    = new double[(srcWidth / wSample) * (srcHeight / hSample)];
            int      index = 0; //非真实的索引号,采样后的

            for (int rowInx = 0; rowInx <= (srcHeight - hSample); rowInx += hSample)
            {
                for (int colInx = 0; colInx <= (srcWidth - wSample); colInx += wSample)
                {
                    xs[index] = srcLeftTopX + colInx * srcResolutionX;
                    ys[index] = srcLeftTopY - rowInx * srcResolutionY;
                    index++;
                }
            }

            if (dstSpatialRef.IsSame(SpatialReferenceFactory.CreateSpatialReference(4326)) == 1)
            {
                projTrans.Transform(xs, ys);
                GeosCorrection(dstSpatialRef, xs, ys);
                maxPrjEnvelope = PrjEnvelope.GetEnvelope(xs, ys, null);
            }
            else
            {
                _rasterProjector.ComputeDstEnvelope(_srcSpatialRef, xs, ys, srcSize, dstSpatialRef, out maxPrjEnvelope,
                                                    null);
            }

            if (_setting != null && _setting.OutEnvelope != null)
            {
                //求交
                maxPrjEnvelope.Intersect(_setting.OutEnvelope);
            }
        }
예제 #2
0
 /// <summary>
 /// 根据给出的经纬度数据集或者投影坐标数据集,计算其是否在指定的范围内,并且计算出有效率,以及实际输出范围
 /// </summary>
 /// <param name="xs"></param>
 /// <param name="ys"></param>
 /// <param name="validEnv"></param>
 /// <param name="oSpatialRef"></param>
 /// <param name="tSpatialRef"></param>
 /// <param name="validRate"></param>
 /// <param name="outEnv"></param>
 /// <returns></returns>
 public bool VaildEnvelope(double[] xs, double[] ys, PrjEnvelope validEnv, SpatialReference oSpatialRef,
                           SpatialReference tSpatialRef, out double validRate, out PrjEnvelope outEnv)
 {
     if (validEnv == null || validEnv.IsEmpty)
     {
         throw new ArgumentNullException("validEnv", "参数[有效范围]不能为空");
     }
     if (tSpatialRef == null)
     {
         tSpatialRef = SpatialReferenceFactory.CreateSpatialReference(4326);
     }
     if (oSpatialRef == null)
     {
         oSpatialRef = SpatialReferenceFactory.CreateSpatialReference(4326);
     }
     using (IProjectionTransform transform =
                ProjectionTransformFactory.GetProjectionTransform(oSpatialRef, tSpatialRef))
     {
         if (oSpatialRef.IsSame(tSpatialRef) != 1)
         {
             transform.Transform(xs, ys);
         }
         return(PrjEnvelope.HasValidEnvelope(xs, ys, validEnv, out validRate, out outEnv));
     }
 }
예제 #3
0
 public FY3L2L3FileProjector()
     : base()
 {
     _name            = "FY3L2L3";
     _fullname        = "FY3L2L3轨道文件投影";
     _rasterProjector = new RasterProjector();
     _srcSpatialRef   = SpatialReferenceFactory.CreateSpatialReference(4326);
 }
예제 #4
0
 public FY2_NOMProjection()
     : base()
 {
     _name            = "FY2NOM";
     _fullname        = "FY2_NOM数据投影";
     _rasterProjector = new RasterProjector();
     _srcSpatialRef   = SpatialReferenceFactory.CreateSpatialReference(4326);
     _supportAngles   = new string[] { "NOMSatelliteZenith", "NOMSunGlintAngle", "NOMSunZenith" };
 }
예제 #5
0
 public FY3_VIRRFileProjector()
     : base()
 {
     _name                = "FY3_VIRR";
     _fullname            = "FY3_VIRR轨道文件投影";
     _rasterProjector     = new RasterProjector();
     _srcSpatialRef       = SpatialReferenceFactory.CreateSpatialReference(4326);
     _supportExtBandNames = new string[] { "Height", "LandCover", "LandSeaMask" };
     //_NODATA_VALUE = 65535;
 }
예제 #6
0
 public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
 {
     if (dstSpatialRef == null || dstSpatialRef.IsGeographic() == 1)
     {
         maxPrjEnvelope = new PrjEnvelope(60, 150, -70, 70, SpatialReferenceFactory.CreateSpatialReference(4326));
     }
     else
     {
         maxPrjEnvelope = null;
     }
 }
예제 #7
0
 public FY3_MERSIFileProjector()
     : base()
 {
     _name            = "FY3_MERSI";
     _fullname        = "FY3_MERSI轨道数据投影";
     _rasterProjector = new RasterProjector();
     _srcSpatialRef   = SpatialReferenceFactory.CreateSpatialReference(4326);
     _left            = 10;
     _right           = 10;
     //_NODATA_VALUE = 65535;
 }
 public FY3B_MERSIFileProjector()
     : base()
 {
     _name                = "FY3B_MERSI";
     _fullname            = "FY3B_MERSI轨道数据投影";
     _rasterProjector     = new RasterProjector();
     _srcSpatialRef       = SpatialReferenceFactory.CreateSpatialReference(4326);
     _left                = 10;
     _right               = 10;
     _supportExtBandNames = new string[] { "DEM", "LandCover", "LandSeaMask" };
     //_NODATA_VALUE = 65535;
 }
예제 #9
0
 private static PrjEnvelopeItem ParseEnvelope(XElement xElement)
 {
     if (xElement == null || xElement.Value == null)
     {
         return(null);
     }
     return(new PrjEnvelopeItem(xElement.Attribute("name").Value,
                                new PrjEnvelope(double.Parse(xElement.Attribute("minx").Value)
                                                , double.Parse(xElement.Attribute("maxx").Value)
                                                , double.Parse(xElement.Attribute("miny").Value)
                                                , double.Parse(xElement.Attribute("maxy").Value)
                                                , SpatialReferenceFactory.CreateSpatialReference(4326))));
 }
예제 #10
0
 public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
 {
     if (srcRaster != null)
     {
         Size     srcSize = new Size(srcRaster.Width, srcRaster.Height);
         double[] xs, ys;
         ReadyLocations(srcRaster, SpatialReferenceFactory.CreateSpatialReference(4326), dstSpatialRef, out srcSize, out xs, out ys, out maxPrjEnvelope, progressCallback);
     }
     else
     {
         maxPrjEnvelope = PrjEnvelope.Empty;
     }
 }
예제 #11
0
 /// <summary>
 /// 经度跨越180度,进行修正
 /// </summary>
 protected void GeosInverCorrection(SpatialReference dstSpatialRef, double[] xs, double[] ys)
 {
     //都是WGS84
     if (dstSpatialRef.IsSame(SpatialReferenceFactory.CreateSpatialReference(4326)) == 1)
     {
         for (int i = 0; i < xs.Length; i++)
         {
             if (xs[i] > 180)
             {
                 xs[i] = xs[i] - 360;
             }
         }
     }
 }
예제 #12
0
        private SpatialReference GetSpatialReference(string projectionIdentify)
        {
            switch (projectionIdentify)
            {
            case "ABS":
                //return SpatialReferenceFactory.GetSpatialReferenceByPrjFile("\\");
                //return new SpatialReference(new GeographicCoordSystem(), new ProjectionCoordSystem());
                return(null);

            case "GLL":
            default:
                return(SpatialReferenceFactory.CreateSpatialReference(4326));
            }
        }
예제 #13
0
 private void DoSession(AbstractWarpDataset srcRaster, AbstractWarpDataset geoRaster, SpatialReference dstSpatialRef, FY3_VIRR_PrjSettings prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession == null || _curSession != srcRaster || _isBeginSession)
     {
         if (progressCallback != null)
         {
             progressCallback(_readyProgress++, "读取及预处理经纬度数据集");
         }
         ReadyLocations(_geoDataProvider, SpatialReferenceFactory.CreateSpatialReference(4326), dstSpatialRef, out _srcLocationSize, out _xs, out _ys, out _maxPrjEnvelope, progressCallback);
         if (progressCallback != null)
         {
             progressCallback(_readyProgress++, "准备其他参数");
         }
         if (prjSettings.IsRadRef || prjSettings.IsRad)
         {
             ReadyRadiationArgs(srcRaster);
         }
         if (prjSettings.IsSolarZenith && prjSettings.IsRadRef)
         {
             _solarZenithCacheFilename = GetSolarZenithCacheFilename(geoRaster.fileName);    //太阳天顶角数据
             if (!File.Exists(_solarZenithCacheFilename))
             {
                 ReadySolarZenithArgsToFile(geoRaster);
             }
             else
             {
                 var ds = Gdal.OpenShared(_solarZenithCacheFilename, Access.GA_ReadOnly);
                 _solarZenithCacheRaster = new WarpDataset(ds, _solarZenithCacheFilename);
             }
             if (prjSettings.IsSensorZenith)
             {
                 ReadySensorZenith(geoRaster);
             }
         }
         _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback);
         _isBeginSession  = false;
     }
 }
예제 #14
0
        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;
        }
예제 #15
0
        protected void ProjectToLDF(Band[] srcBands, Band[] dstBands, int beginBandIndex, Action <int, string> progressCallback)
        {
            //progressCallback = progressCallback;
            if (srcBands == null || srcBands[0].XSize == 0 || srcBands[0].YSize == 0)
            {
                throw new Exception("投影数据失败:无法读取源数据,或者源数据高或宽为0。");
            }
            Size  srcImgSize        = new Size(srcBands[0].XSize, srcBands[0].YSize);
            Size  outSize           = _dstEnvelope.GetSize(_outResolutionX, _outResolutionY);
            float bufferResolutionX = 0f;
            float bufferResolutionY = 0f;
            float outXScale         = _srcImgResolution / _outResolutionX;
            float outYScale         = _srcImgResolution / _outResolutionY;

            if (outXScale > 1.5f || outYScale > 1.5f)
            {
                bufferResolutionX = _srcImgResolution;
                bufferResolutionY = _srcImgResolution;
            }
            else
            {
                bufferResolutionX = _outResolutionX;
                bufferResolutionY = _outResolutionY;
            }
            int blockXCount;
            int blockYCount;
            int blockWidth;
            int blockHeight;

            //后面投影需要的内存:(double)经纬度数据、(int16)原始通道数据、(int16)投影后通道、(int16)其他(如角度数据等)
            GetBlockNumber(outSize, _srcLocationSize, outXScale, outYScale, out blockXCount, out blockYCount, out blockWidth, out blockHeight);
            int imgLocationRatioX = srcImgSize.Width / _srcLocationSize.Width;
            int imgLocationRatioY = srcImgSize.Height / _srcLocationSize.Height;

            progressCount = blockYCount * blockXCount * (_dstBandCount + (_angleBands == null ? 0 : _angleBands.Length) + (_extSrcBands == null ? 0 : _extSrcBands.Length));
            progress      = 0;
            percent       = 0;
            Size bufferSize;

            #region 在需要分块的情况下,采样经纬度数据集
            int      bC        = 1;
            int      tmpWidth  = 0;
            int      tmpHeight = 0;
            double[] tmpxs     = null;
            double[] tmpys     = null;
            if (blockYCount * blockXCount > 1 && (_xs == null || _ys == null))
            {
                bC        = (int)Math.Sqrt(blockXCount * blockYCount) + 1;
                tmpWidth  = _srcLocationSize.Width / bC;
                tmpHeight = _srcLocationSize.Height / bC;
                tmpxs     = ReadSampleDatas(_longitudeBand, 0, 0, tmpWidth, tmpHeight);
                tmpys     = ReadSampleDatas(_latitudeBand, 0, 0, tmpWidth, tmpHeight);
                TryApplyGeoInterceptSlope(tmpxs, tmpys);
                _rasterProjector.Transform(SpatialReferenceFactory.CreateSpatialReference(4326), tmpxs, tmpys, _dstSpatialRef);
            }
            #endregion

            for (int blockXNo = 0; blockXNo < blockXCount; blockXNo++)
            {
                for (int blockYNo = 0; blockYNo < blockYCount; blockYNo++)
                {
                    //起始偏移,结束偏移
                    int beginX = blockWidth * blockXNo;
                    int beginY = blockHeight * blockYNo;
                    if (beginX >= outSize.Width || beginY >= outSize.Height)
                    {
                        continue;
                    }
                    if (beginX + blockWidth > outSize.Width)
                    {
                        blockWidth = outSize.Width - beginX;
                    }
                    if (beginY + blockHeight > outSize.Height)
                    {
                        blockHeight = outSize.Height - beginY;
                    }

                    //当前块的四角范围
                    double      blockMinX     = _dstEnvelope.MinX + beginX * _outResolutionX;
                    double      blockMaxX     = blockMinX + blockWidth * _outResolutionX;
                    double      blockMaxY     = _dstEnvelope.MaxY - beginY * _outResolutionY;
                    double      blockMinY     = blockMaxY - blockHeight * _outResolutionY;
                    PrjEnvelope blockEnvelope = new PrjEnvelope(blockMinX, blockMaxX, blockMinY, blockMaxY, _dstSpatialRef);
                    bufferSize = blockEnvelope.GetSize(bufferResolutionX, bufferResolutionY);
                    //根据当前输出块,反算出对应的源数据块(轨道)起始行列,为了减小后面需要读取的源数据大小
                    Block curOrbitblock = null;
                    //开始获取当前分块的经纬度数据集,计算轨道数据范围偏移
                    double[] srcBlockXs;
                    double[] srcBlockYs;
                    if (blockYCount == 1 && blockXCount == 1)                           //没分块的情况
                    {
                        curOrbitblock = _orbitBlock.Clone() as Block;
                        if (curOrbitblock.xBegin < _left)
                        {
                            curOrbitblock.xBegin = _left;
                        }
                        if (curOrbitblock.xEnd > _srcLocationSize.Width - 1 - _right)
                        {
                            curOrbitblock.xEnd = _srcLocationSize.Width - 1 - _right;
                        }
                        if (curOrbitblock.Width == _srcLocationSize.Width && curOrbitblock.Height == _srcLocationSize.Height)
                        {
                            if (_xs != null && _ys != null)
                            {
                                srcBlockXs = _xs;
                                srcBlockYs = _ys;
                            }
                            else
                            {
                                srcBlockXs = ReadBlockDatas(_longitudeBand, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                                srcBlockYs = ReadBlockDatas(_latitudeBand, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);

                                TryApplyGeoInterceptSlope(srcBlockXs, srcBlockYs);
                                _rasterProjector.Transform(SpatialReferenceFactory.CreateSpatialReference(4326), srcBlockXs, srcBlockYs, _dstSpatialRef);
                            }
                        }
                        else
                        {
                            if (_xs != null && _ys != null)
                            {
                                GetBlockDatas(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height, out srcBlockXs, out srcBlockYs);
                            }
                            else
                            {
                                srcBlockXs = ReadBlockDatas(_longitudeBand, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                                srcBlockYs = ReadBlockDatas(_latitudeBand, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                                TryApplyGeoInterceptSlope(srcBlockXs, srcBlockYs);
                                _rasterProjector.Transform(SpatialReferenceFactory.CreateSpatialReference(4326), srcBlockXs, srcBlockYs, _dstSpatialRef);
                            }
                        }
                    }
                    else
                    {
                        if (_xs != null && _ys != null)
                        {
                            GetEnvelope(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, blockEnvelope, out curOrbitblock);
                        }
                        else
                        {
                            //计算偏移。
                            GetEnvelope(tmpxs, tmpys, tmpWidth, tmpHeight, blockEnvelope, out curOrbitblock);
                            curOrbitblock = curOrbitblock.Zoom(bC, bC);
                        }
                        if (curOrbitblock.Width <= 0 || curOrbitblock.Height <= 0)      //当前分块不在图像内部
                        {
                            progress += _dstBandCount;
                            continue;
                        }
                        if (curOrbitblock.xBegin < _left)
                        {
                            curOrbitblock.xBegin = _left;
                        }
                        if (curOrbitblock.xEnd > _srcLocationSize.Width - 1 - _right)
                        {
                            curOrbitblock.xEnd = _srcLocationSize.Width - 1 - _right;
                        }
                        if (_xs != null && _ys != null)
                        {
                            GetBlockDatas(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height, out srcBlockXs, out srcBlockYs);
                        }
                        else
                        {
                            srcBlockXs = ReadBlockDatas(_longitudeBand, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                            srcBlockYs = ReadBlockDatas(_latitudeBand, curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                            TryApplyGeoInterceptSlope(srcBlockXs, srcBlockYs);
                            _rasterProjector.Transform(SpatialReferenceFactory.CreateSpatialReference(4326), srcBlockXs, srcBlockYs, _dstSpatialRef);
                        }
                    }
                    int  srcBlockJdWidth      = curOrbitblock.Width;
                    int  srcBlockJdHeight     = curOrbitblock.Height;
                    int  srcBlockImgWidth     = curOrbitblock.Width * imgLocationRatioX;
                    int  srcBlockImgHeight    = curOrbitblock.Height * imgLocationRatioY;
                    Size srcBlockLocationSize = new Size(srcBlockJdWidth, srcBlockJdHeight);
                    Size srcBlockImgSize      = new Size(srcBlockImgWidth, srcBlockImgHeight);
                    //亮温订正,天顶角修正:下面获取用到的部分经纬度和太阳高度角修正系数数据,下面修改为从临时文件直接读取。
                    float[] solarZenithData = null;
                    if (_isRadRef && _isSolarZenith)
                    {
                        if (_solarZenithCacheRaster != null)    //太阳天顶角数据
                        {
                            ReadBandData(out solarZenithData, _solarZenithCacheRaster, 1, curOrbitblock.xBegin, curOrbitblock.yBegin, srcBlockJdWidth, srcBlockJdHeight);
                        }
                        //亮温临边变暗订正,读取卫星天顶角数据。
                        //if (_isSensorZenith)
                        //    ReadBandData(out _sensorZenithData, _sensorSenithBand, curOrbitblock.xOffset, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                        TryReadZenithData(curOrbitblock.xBegin, curOrbitblock.yBegin, curOrbitblock.Width, curOrbitblock.Height);
                    }

                    //计算当前分块的投影查算表
                    UInt16[] dstRowLookUpTable = new UInt16[bufferSize.Width * bufferSize.Height];
                    UInt16[] dstColLookUpTable = new UInt16[bufferSize.Width * bufferSize.Height];
                    if (imgLocationRatioX == 1)
                    {
                        _rasterProjector.ComputeIndexMapTable(srcBlockXs, srcBlockYs, srcBlockImgSize, bufferSize, blockEnvelope, _maxPrjEnvelope,
                                                              out dstRowLookUpTable, out dstColLookUpTable, null);
                    }
                    else
                    {
                        _rasterProjector.ComputeIndexMapTable(srcBlockXs, srcBlockYs, srcBlockLocationSize, srcBlockImgSize, bufferSize, blockEnvelope, //_maxPrjEnvelope,
                                                              out dstRowLookUpTable, out dstColLookUpTable, null, 0);
                    }
                    //执行投影
                    UInt16[] srcBandData = null;
                    UInt16[] dstBandData = new UInt16[bufferSize.Width * bufferSize.Height];
                    for (int i = 0; i < srcBands.Length; i++)  //读取原始通道值,投影到目标区域
                    {
                        if (progressCallback != null)
                        {
                            progress++;
                            percent = (int)(progress * 100 / progressCount);
                            progressCallback(percent, string.Format("投影完成{0}%", percent));
                        }
                        ReadImgBand(srcBands[i], curOrbitblock.xBegin * imgLocationRatioX, curOrbitblock.yBegin * imgLocationRatioY, srcBlockImgWidth, srcBlockImgHeight,
                                    new Size(srcBlockImgWidth, srcBlockImgHeight), out srcBandData);
                        //ReadImgBand(out srcBandData, i, curOrbitblock.xOffset * imgLocationRatioX, curOrbitblock.yBegin * imgLocationRatioY, srcBlockImgWidth, srcBlockImgHeight);
                        Size angleSize = new Size(srcBlockJdWidth, srcBlockJdHeight);

                        DoRadiation(srcBands[i], srcBandData, solarZenithData, srcBlockImgSize, angleSize);

                        _rasterProjector.Project <UInt16>(srcBandData, srcBlockImgSize, dstRowLookUpTable, dstColLookUpTable, bufferSize, dstBandData, 0, null);
                        srcBandData = null;
                        Band band = dstBands[i];
                        unsafe
                        {
                            fixed(UInt16 *ptr = dstBandData)
                            {
                                IntPtr bufferPtr    = new IntPtr(ptr);
                                int    blockOffsetY = blockHeight * blockYNo;
                                int    blockOffsetX = blockWidth * blockXNo;

                                band.WriteRaster(blockOffsetX, blockOffsetY, blockWidth, blockHeight, bufferPtr, bufferSize.Width, bufferSize.Height, DataType.GDT_UInt16, 0, 0);
                            }
                        }
                    }
                    srcBandData = null;
                    dstBandData = null;
                    GC.Collect();
                    ReleaseZenithData();
                    Size srcBufferSize = new Size(srcBlockImgWidth, srcBlockImgHeight);
                    ProjectAngle(bufferSize, srcBufferSize, blockWidth, blockHeight, blockYNo, blockXNo, curOrbitblock, dstRowLookUpTable, dstColLookUpTable, progressCallback);
                    ProjectExtBands(bufferSize, srcBufferSize, blockWidth, blockHeight, blockYNo, blockXNo, curOrbitblock, dstRowLookUpTable, dstColLookUpTable, progressCallback);
                    dstRowLookUpTable = null;
                    dstColLookUpTable = null;
                }
            }
        }
예제 #16
0
        private static PrjEnvelopeItem[] ParseEnvelopes(XElement xElement)
        {
            if (xElement == null || xElement.Elements("Envelope") == null)
            {
                return(null);
            }
            IEnumerable <PrjEnvelopeItem> prjs = from item in xElement.Elements("Envelope")
                                                 select new PrjEnvelopeItem(item.Attribute("name").Value,
                                                                            new PrjEnvelope(double.Parse(item.Attribute("minx").Value)
                                                                                            , double.Parse(item.Attribute("minx").Value)
                                                                                            , double.Parse(item.Attribute("minx").Value)
                                                                                            , double.Parse(item.Attribute("minx").Value)
                                                                                            , SpatialReferenceFactory.CreateSpatialReference(4326)));

            return(prjs.ToArray());
        }
예제 #17
0
        private void ReadyArgs(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings, SpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            float resolutionScale = 1f;

            _readyProgress = 0;
            if (progressCallback != null)
            {
                progressCallback(_readyProgress++, "准备相关参数");
            }
            _prjSettings     = ArgsCheck(srcRaster, prjSettings);
            _geoDataProvider = _prjSettings.GeoFile;
            CheckIs0250(srcRaster);
            _dstSpatialRef = dstSpatialRef;
            switch (_dataType)
            {
            case "1KM":
                //整轨投影时候去除左右锯齿,分块投影不需要
                _left  = 10;
                _right = 10;
                if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty)    //整轨投影时做限制
                {
                    MemoryHelper.MemoryNeed(500, 1536);
                }
                else
                {
                    MemoryHelper.MemoryNeed(400, 1536);          //剩余900MB,已使用1.2GB
                }
                //_angleDataProvider = srcRaster;
                TryCreateDefaultArgs(srcRaster, _prjSettings, ref _dstSpatialRef);
                TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs);
                DoSession(srcRaster, _geoDataProvider, _dstSpatialRef, _prjSettings, progressCallback);
                break;

            case "QKM":
                resolutionScale = 4f;
                _left           = 20;
                _right          = 20;
                if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty)
                {
                    MemoryHelper.MemoryNeed(800, 1280);         //整幅投影对内存做限制,系统剩余内存不低于A参数MB,应用程序已使用内存不超过B参数MB
                }
                else
                {
                    MemoryHelper.MemoryNeed(600, 1280);         //剩余900MB,最大已使用1.2GB
                }
                //_angleDataProvider = _prjSettings.SecondaryOrbitRaster;
                TryCreate0250DefaultArgs(srcRaster, _prjSettings, ref _dstSpatialRef);
                TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs);
                DoSession(srcRaster, _geoDataProvider, _dstSpatialRef, _prjSettings, progressCallback);
                break;

            default:
                break;
            }
            if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty)
            {
                _prjSettings.OutEnvelope = _maxPrjEnvelope;
                _orbitBlock = new Block {
                    xBegin = 0, yBegin = 0, xEnd = _srcLocationSize.Width - 1, yEnd = _srcLocationSize.Height - 1
                };
            }
            else
            {
                if (_xs != null && _ys != null)
                {
                    GetEnvelope(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, _prjSettings.OutEnvelope, out _orbitBlock);
                }
                else
                {
                    int      bC        = 8;
                    int      tmpWidth  = 0;
                    int      tmpHeight = 0;
                    double[] tmpxs     = null;
                    double[] tmpys     = null;
                    //8024,8000
                    tmpWidth  = _srcLocationSize.Width / bC;
                    tmpHeight = _srcLocationSize.Height / bC;
                    tmpxs     = ReadSampleDatas(_longitudeBand, 0, 0, tmpWidth, tmpHeight);
                    tmpys     = ReadSampleDatas(_latitudeBand, 0, 0, tmpWidth, tmpHeight);
                    _rasterProjector.Transform(SpatialReferenceFactory.CreateSpatialReference(4326), tmpxs, tmpys, _dstSpatialRef);
                    //计算偏移
                    GetEnvelope(tmpxs, tmpys, tmpWidth, tmpHeight, _prjSettings.OutEnvelope, out _orbitBlock);
                    _orbitBlock = _orbitBlock.Zoom(bC, bC);
                    tmpxs       = new double[1];
                    tmpys       = new double[1];
                }
                if (_orbitBlock == null || _orbitBlock.Width <= 0 || _orbitBlock.Height <= 0)
                {
                    throw new Exception("数据不在目标区间内");
                }
                float invalidPresent = (_orbitBlock.Width * _orbitBlock.Height * resolutionScale) / (_srcLocationSize.Width * _srcLocationSize.Height);
                if (invalidPresent < 0.0001f)
                {
                    throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%");
                }
                if (invalidPresent > 0.60)
                {
                    _orbitBlock = new Block {
                        xBegin = 0, yBegin = 0, xEnd = _srcLocationSize.Width - 1, yEnd = _srcLocationSize.Height - 1
                    }
                }
                ;
            }
            //地理坐标投影,下面简单的对地理坐标投影的范围作了限制,不大严谨,仅适合目前的状况。
            //if (_dstSpatialRef.IsGeographic()==1 && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80))
            //{
            //    throw new Exception(string.Format("高纬度数据,不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope));
            //}
            //以下参数用于投影

            _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   = _prjBands.Length;
            _dstSize        = _prjSettings.OutSize;
            _isRadRef       = _prjSettings.IsRadRef;
            _isSolarZenith  = _prjSettings.IsSolarZenith;
            _isSensorZenith = _prjSettings.IsSensorZenith;
            _isRad          = _prjSettings.IsRad;
        }
예제 #18
0
 public DefinedRegionParse()
 {
     LoadConfig();
     wgs84 = SpatialReferenceFactory.CreateSpatialReference(4326);
 }
예제 #19
0
 private PrjEnvelope CoordToEnvelope(Envelope coordEnvelope)
 {
     return(new PrjEnvelope(coordEnvelope.MinX, coordEnvelope.MaxX, coordEnvelope.MinY, coordEnvelope.MaxY,
                            SpatialReferenceFactory.CreateSpatialReference(4326)));
 }
예제 #20
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (AbstractWarpDataset inputRaster = WarpDataset.Open(inArg.InputFilename))
                {
                    RasterDatasetInfo dsInfo =
                        mRasterSourceManager.GetInstance().GetRasterDatasetInfo(inArg.InputFilename);
                    DateTime?    dateTime     = mRasterSourceManager.GetInstance().GetImageTime(inArg.InputFilename);
                    DataIdentify dataIdentify = new DataIdentify();
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dsInfo.SatelliteID;
                    outArg.Sensor             = dsInfo.SensorID;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dateTime.HasValue ? dateTime.Value.ToString("yyyyMMdd") : "";
                    outArg.ObservationTime    = dateTime.HasValue ? dateTime.Value.ToString("HHmm") : "";
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    if (dateTime.HasValue)
                    {
                        outArg.OrbitIdentify = CalcOrbitIdentify(dateTime.Value, inArg.PervObservationDate,
                                                                 inArg.PervObservationTime, inArg.OrbitIdentify);
                    }
                    outArg.Length = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";

                    #region 日夜检查

                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }

                    #endregion 日夜检查

                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        PrjOutArg prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY,
                                                   inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX,
                                                   inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }

                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress),
                                                                          out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg fileArg = new OutFileArg();
                            Envelope   env     = null;
                            float      resolutionX;
                            float      resolutionY;
                            string     overViewFilename = "";
                            using (AbstractWarpDataset outfileRaster = WarpDataset.Open(file))
                            {
                                Console.WriteLine("生成缩略图开始");
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                Console.WriteLine("生成缩略图结束");
                                env         = outfileRaster.GetEnvelope();
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                var dt = dateTime.HasValue ? dateTime.Value : DateTime.Now;
                                TryMosaicFile(inArg, outfileRaster, dsInfo, dt, outArg.DayOrNight);
                            }

                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      =
                                (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename)
                                    ? ""
                                    : Path.GetFileName(overViewFilename));
                            string solarZenithFile = Path.Combine(Path.GetDirectoryName(file),
                                                                  Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file),
                                                                     Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) &&
                                                   File.Exists(solarZenithFile)
                                                      ? ""
                                                      : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) &&
                                                   File.Exists(solarZenithHdrFile)
                                                      ? ""
                                                      : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope = new PrjEnvelopeItem("GBAL",
                                                                   env == null
                                    ? null
                                    : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY,
                                                                    SpatialReferenceFactory.CreateSpatialReference(4326)));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }

                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                Console.WriteLine(ex.StackTrace);
                outArg.LogInfo = ex.Message + ex.StackTrace;
                Console.WriteLine("PIE.Meteo.ProjectTool.Execute()", ex);
            }
            finally
            {
                //输出参数文件重新命名
                string inputFileName = Path.GetFileName(inArg.InputFilename);

                System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"_\d{4}M");
                if (rex.IsMatch(inputFileName))
                {
                    string oldResStr = rex.Match(inputFileName).Groups[0].Value;
                    if (inArg.ProjectionIdentify == "GLL")
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.GLLResolutionIdentify(inArg.ResolutionX)}");
                    }
                    else
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.ResolutionIdentify(inArg.ResolutionX)}");
                    }
                }

                string outXmlFilename = Path.Combine(inArg.OutputDir, inputFileName + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }