示例#1
0
        private bool IsInteractived(CoordEnvelope envelopeA, CoordEnvelope envelopeB)
        {
            PrjEnvelope prja = new PrjEnvelope(envelopeA.MinX, envelopeA.MaxX, envelopeA.MinY, envelopeA.MaxY);
            PrjEnvelope prjb = new PrjEnvelope(envelopeB.MinX, envelopeB.MaxX, envelopeB.MinY, envelopeB.MaxY);

            return(prja.IntersectsWith(prjb));
        }
示例#2
0
        //源为待裁切的文件,目标为裁切输出的小文件
        public static bool ComputeBeginEndRowCol(PrjEnvelope oEnvelope, Size oSize, PrjEnvelope tEnvelope, Size tSize,
                                                 ref int oBeginRow, ref int oBeginCol, ref int oEndRow, ref int oEndCol,
                                                 ref int tBeginRow, ref int tBeginCol, ref int tEndRow, ref int tEndCol)
        {
            if (!oEnvelope.IntersectsWith(tEnvelope))
            {
                return(false);
            }
            double resolutionX = oEnvelope.Width / oSize.Width;
            double resolutionY = oEnvelope.Height / oSize.Height;

            if (oEnvelope.MinX >= tEnvelope.MinX)//左边界在目标图像内部
            {
                oBeginCol = 0;
                tBeginCol = (int)((oEnvelope.MinX - tEnvelope.MinX) / resolutionX + 0.5);
            }
            else//左边界在目标图像外部
            {
                oBeginCol = (int)((tEnvelope.MinX - oEnvelope.MinX) / resolutionX + 0.5);
                tBeginCol = 0;
            }
            if (oEnvelope.MaxX >= tEnvelope.MaxX)//右边界在目标图像外部
            {
                oEndCol = (int)((tEnvelope.MaxX - oEnvelope.MinX) / resolutionX + 0.5);
                tEndCol = tSize.Width;
            }
            else//右边界在目标图像内部
            {
                oEndCol = (int)((oEnvelope.MaxX - oEnvelope.MinX) / resolutionX + 0.5);
                tEndCol = (int)((oEnvelope.MaxX - tEnvelope.MinX) / resolutionX + 0.5);
            }
            if (oEnvelope.MaxY <= tEnvelope.MaxY)//上边界在目标图像内部
            {
                oBeginRow = 0;
                tBeginRow = (int)((tEnvelope.MaxY - oEnvelope.MaxY) / resolutionY + 0.5);
            }
            else//上边界在目标边界外部
            {
                oBeginRow = (int)((oEnvelope.MaxY - tEnvelope.MaxY) / resolutionY + 0.5);
                tBeginRow = 0;
            }
            if (oEnvelope.MinY <= tEnvelope.MinY)//下边界在目标图像外部
            {
                oEndRow = (int)((oEnvelope.MaxY - tEnvelope.MinY) / resolutionY + 0.5);
                tEndRow = tSize.Height;
            }
            else//下边界在目标图像内部
            {
                oEndRow = oSize.Height;
                tEndRow = (int)((tEnvelope.MaxY - oEnvelope.MinY) / resolutionY + 0.5);
            }
            return(true);
        }
        private void Project(IRasterDataProvider srcRaster, NOAA_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("数据不在目标区间内");
            }
        }
示例#4
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");
     }
     if (progressCallback != null)
     {
         progressCallback(0, "准备相关参数");
     }
     _dstSpatialRef = dstSpatialRef;
     if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty)
     {
         MemoryHelper.MemoryNeed(200, 1536);
     }
     else
     {
         MemoryHelper.MemoryNeed(200, 1536);     //剩余900MB,已使用1.2GB
     }
     try
     {
         NOAA_PrjSettings noaaPrjSettings = prjSettings as NOAA_PrjSettings;
         TryCreateDefaultArgs(srcRaster, noaaPrjSettings, ref dstSpatialRef);
         _isSensorZenith = noaaPrjSettings.IsSensorZenith;
         DoSession(srcRaster, dstSpatialRef, noaaPrjSettings, 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 && _maxPrjEnvelope.MaxX > 180 && _maxPrjEnvelope.MinX < -180 && _maxPrjEnvelope.MaxY > 90 && _maxPrjEnvelope.MinY < -90)
         {
             throw new Exception("读取FY1X 1a5经纬度不在合理范围内[" + _maxPrjEnvelope.ToString() + "]");
         }
         //if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80))
         //    throw new Exception(string.Format("高纬度数据[>80],不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope));
         PrjEnvelope envelops = prjSettings.OutEnvelope;
         if (!envelops.IntersectsWith(_maxPrjEnvelope))
         {
             throw new Exception("数据不在目标区间内");
         }
         float    outResolutionX = prjSettings.OutResolutionX;
         float    outResolutionY = prjSettings.OutResolutionY;
         int      dstBandCount   = prjSettings.OutBandNos.Length;
         Size     outSize        = prjSettings.OutSize;
         string[] angleOptions   = new string[] {
             "INTERLEAVE=BSQ",
             "VERSION=LDF",
             "WITHHDR=TRUE",
             "SPATIALREF=" + dstSpatialRef.ToProj4String(),
             "MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + outResolutionX + "," + outResolutionY + "}"
         };
         string outfilename = prjSettings.OutPathAndFileName;
         ReadyAngleFiles(srcRaster, outfilename, prjSettings, outSize, angleOptions);
         Project(srcRaster, noaaPrjSettings, dstSpatialRef, progressCallback);
     }
     catch
     {
         EndSession();
         TryDeleteCurCatch();
         throw;
     }
     finally
     {
         if (_curSession == null)
         {
             EndSession();
             if (prjSettings.IsClearPrjCache)
             {
                 TryDeleteCurCatch();
             }
         }
     }
 }