Exemplo n.º 1
0
        public static Rectangle ToRasterRect(this IRasterDataProvider dataProvider, CoordEnvelope dataCoordEnvelope)
        {
            CoordEnvelope evp = dataProvider.CoordEnvelope.Intersect(dataCoordEnvelope);

            if (evp == null || evp.IsEmpty())
            {
                return(Rectangle.Empty);
            }
            double resX = dataProvider.CoordEnvelope.Width / dataProvider.Width;
            double resY = dataProvider.CoordEnvelope.Height / dataProvider.Height;
            double x    = (evp.MinX - dataCoordEnvelope.MinX) / resX;
            double y    = (evp.MaxY - dataCoordEnvelope.MaxY) / resY;
            double w    = evp.Width / resX;
            double h    = evp.Height / resY;

            return(new Rectangle((int)x, (int)y, (int)w, (int)h));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 支持不同分辨率的拼接
        /// </summary>
        /// <param name="args"></param>
        /// <param name="dstArgs"></param>
        /// <param name="tSize"></param>
        /// <param name="oBeginRow"></param>
        /// <param name="oBeginCol"></param>
        /// <param name="oIntersectSize"></param>
        /// <param name="tBeginRow"></param>
        /// <param name="tBeginCol"></param>
        /// <param name="tIntersectSize"></param>
        /// <returns></returns>
        public static bool ComputeBeginEndRowCol(IRasterDataProvider args, IRasterDataProvider dstArgs,
                                                 ref int oBeginRow, ref int oBeginCol, ref Size oIntersectSize,
                                                 ref int tBeginRow, ref int tBeginCol, ref Size tIntersectSize)
        {
            CoordEnvelope oEnvelope = args.CoordEnvelope;
            CoordEnvelope tEnvelope = dstArgs.CoordEnvelope;
            CoordEnvelope inEnv     = oEnvelope.Intersect(tEnvelope);

            if (inEnv == null || inEnv.IsEmpty())
            {
                return(false);
            }
            if (!IsInteractived(oEnvelope, tEnvelope))
            {
                return(false);
            }
            float oResolutionX = args.ResolutionX;
            float oResolutionY = args.ResolutionY;
            float tResolutionX = dstArgs.ResolutionX;
            float tResolutionY = dstArgs.ResolutionY;

            oIntersectSize = CoordEnvelopeToSize(inEnv, oResolutionX, oResolutionY);
            tIntersectSize = CoordEnvelopeToSize(inEnv, tResolutionX, tResolutionY);
            //
            if (oEnvelope.MinX >= tEnvelope.MinX)//左边界在目标图像内部
            {
                oBeginCol = 0;
                tBeginCol = (int)((oEnvelope.MinX - tEnvelope.MinX) / tResolutionX + _errorValue);
            }
            else//左边界在目标图像外部
            {
                oBeginCol = (int)((tEnvelope.MinX - oEnvelope.MinX) / oResolutionX + _errorValue);
                tBeginCol = 0;
            }
            if (oEnvelope.MaxY <= tEnvelope.MaxY)//上边界在目标图像内部
            {
                oBeginRow = 0;
                tBeginRow = (int)((tEnvelope.MaxY - oEnvelope.MaxY) / tResolutionY + _errorValue);
            }
            else//上边界在目标边界外部
            {
                oBeginRow = (int)((oEnvelope.MaxY - tEnvelope.MaxY) / oResolutionY + _errorValue);
                tBeginRow = 0;
            }
            Size oSize = new Size(args.Width, args.Height);
            Size tSize = new Size(dstArgs.Width, dstArgs.Height);

            //以下添加对偏移计算的纠正,取最小行列数
            if (oIntersectSize.Width + oBeginCol > oSize.Width)
            {
                oIntersectSize.Width = oSize.Width - oBeginCol;
            }
            if (oIntersectSize.Height + oBeginRow > oSize.Height)
            {
                oIntersectSize.Height = oSize.Height - oBeginRow;
            }
            if (tIntersectSize.Width + tBeginCol > tSize.Width)
            {
                tIntersectSize.Width = tSize.Width - tBeginCol;
            }
            if (tIntersectSize.Height + tBeginRow > tSize.Height)
            {
                tIntersectSize.Height = tSize.Height - tBeginRow;
            }
            return(true);
        }
Exemplo n.º 3
0
        public IInterestedRaster <T> CycleTimes(IRasterDataProvider[] srcRasters, RasterIdentify rasterIdentify, Func <int, T, T, T> iTimesGetter, Action <int, string> progress)
        {
            ////修改不同区域生成结果文件大小不足问题 by chennan 20120806
            //CoordEnvelope dstEnvelope = srcRasters[srcRasters.Length - 1].CoordEnvelope;
            CoordEnvelope dstEnvelope    = GetEnvelopeBySize(srcRasters[srcRasters.Length - 1]);
            float         minResolutionX = 0f;
            float         minResolutionY = 0f;
            Size          dstSize        = Size.Empty;;

            for (int i = 0; i < srcRasters.Length - 1; i++)
            {
                if (srcRasters[i].DataType != srcRasters[i + 1].DataType)
                {
                    throw new ArgumentException("数据类型不一致无法进行频次统计!");
                }
                dstEnvelope = dstEnvelope.Union(GetEnvelopeBySize(srcRasters[i]));
                // by chennan 20120806
                minResolutionX = Math.Min(srcRasters[i].ResolutionX, srcRasters[i + 1].ResolutionX);
                minResolutionY = Math.Min(srcRasters[i].ResolutionY, srcRasters[i + 1].ResolutionY);
                dstSize        = new Size((int)Math.Floor(dstEnvelope.Width / minResolutionX), (int)Math.Floor(dstEnvelope.Height / minResolutionY));
            }
            //by chennan 20121025 修改单文件无法进行周期统计
            if (srcRasters.Length == 1)
            {
                minResolutionX = srcRasters[0].ResolutionX;
                minResolutionY = srcRasters[0].ResolutionY;
                dstEnvelope    = srcRasters[0].CoordEnvelope.Clone();
                dstSize        = new Size(srcRasters[0].Width, srcRasters[0].Height);
            }
            IInterestedRaster <T> dstRaster = CreateDstRaster(srcRasters[0], dstEnvelope, rasterIdentify, dstSize);
            IArgumentProvider     argprd = new ArgumentProvider(new AlgorithmDef());
            int offsetX = 0, offsetY = 0;
            int dstIndex = 0;
            int index = 0;

            foreach (IRasterDataProvider rst in srcRasters)
            {
                if (progress != null)
                {
                    progress((int)(index++ *100f / srcRasters.Length), "正在执行周期统计");
                }
                CoordEnvelope inc = rst.CoordEnvelope.Intersect(dstEnvelope);
                if (inc == null || inc.IsEmpty())
                {
                    continue;
                }
                int iCycle = Array.IndexOf <IRasterDataProvider>(srcRasters, rst) + 1;
                offsetX = (int)((rst.CoordEnvelope.MinX - dstEnvelope.MinX) / rst.ResolutionX);
                offsetY = (int)((dstEnvelope.MaxY - rst.CoordEnvelope.MaxY) / rst.ResolutionY);
                //by chennan 20120806
                IRasterDataProvider dstTempPrd = GetSubPrd <T>(dstRaster.HostDataProvider, rst, rasterIdentify, offsetX, offsetY);
                try
                {
                    IVirtualRasterDataProvider virtualDataProvider = new VirtualRasterDataProvider(new IRasterDataProvider[] { dstTempPrd, rst });
                    argprd.DataProvider = virtualDataProvider;
                    using (IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argprd))
                    {
                        visitor.VisitPixel(new int[] { 1, 2 },
                                           (idx, values) =>
                        {
                            dstIndex = (idx / dstTempPrd.Width + offsetY) * dstRaster.HostDataProvider.Width + (idx % dstTempPrd.Width + offsetX);
                            dstRaster.Put(dstIndex, iTimesGetter(iCycle, values[0], values[1]));
                        });
                    }
                }
                finally
                {
                    dstTempPrd.Dispose();
                    if (File.Exists(dstTempPrd.fileName))
                    {
                        File.Delete(dstTempPrd.fileName);
                    }
                }
            }
            for (int i = 0; i < srcRasters.Length; i++)
            {
                srcRasters[i].Dispose();
            }
            return(dstRaster);
        }
Exemplo n.º 4
0
        public bool ComputeBeginEndRowCol(IRasterDataProvider args, IRasterDataProvider dstArgs, Size targetSize, ref int oBeginRow, ref int oBeginCol, ref int oEndRow, ref int oEndCol, ref int tBeginRow, ref int tBeginCol, ref int tEndRow, ref int tEndCol)
        {
            CoordEnvelope targetEnvelope = dstArgs.CoordEnvelope;
            CoordEnvelope innerEnvelope  = targetEnvelope.Intersect(args.CoordEnvelope);

            if (innerEnvelope == null || innerEnvelope.IsEmpty())
            {
                return(false);
            }
            double        tResolutionX = dstArgs.ResolutionX;
            double        tResolutionY = dstArgs.ResolutionY;
            double        oResolutionX = args.ResolutionX;
            double        oResolutionY = args.ResolutionY;
            CoordEnvelope oEnvelope    = args.CoordEnvelope;

            //
            if (oEnvelope.MinX >= targetEnvelope.MinX)//左边界在目标图像内部
            {
                oBeginCol = 0;
                tBeginCol = (int)((oEnvelope.MinX - targetEnvelope.MinX) / tResolutionX + _errorValue);
            }
            else//左边界在目标图像外部
            {
                oBeginCol = (int)((targetEnvelope.MinX - oEnvelope.MinX) / oResolutionX + _errorValue);
                tBeginCol = 0;
            }
            if (oEnvelope.MaxX >= targetEnvelope.MaxX)//右边界在目标图像外部
            {
                oEndCol = (int)((targetEnvelope.MaxX - oEnvelope.MinX) / oResolutionX + _errorValue);
                tEndCol = targetSize.Width;
            }
            else//右边界在目标图像内部
            {
                oEndCol = (int)((args.CoordEnvelope.MaxX - args.CoordEnvelope.MinX) / oResolutionX + _errorValue);
                tEndCol = (int)((oEnvelope.MaxX - targetEnvelope.MinX) / tResolutionX + _errorValue);
            }
            if (oEnvelope.MaxY <= targetEnvelope.MaxY)//上边界在目标图像内部
            {
                oBeginRow = 0;
                tBeginRow = (int)((targetEnvelope.MaxY - oEnvelope.MaxY) / tResolutionY + _errorValue);
            }
            else//上边界在目标边界外部
            {
                oBeginRow = (int)((oEnvelope.MaxY - targetEnvelope.MaxY) / oResolutionY + _errorValue);
                tBeginRow = 0;
            }
            if (oEnvelope.MinY <= targetEnvelope.MinY)//下边界在目标图像外部
            {
                oEndRow = (int)((oEnvelope.MaxY - targetEnvelope.MinY) / oResolutionY + _errorValue);
                tEndRow = targetSize.Height;
            }
            else//下边界在目标图像内部
            {
                oEndRow = args.Height;
                tEndRow = (int)((targetEnvelope.MaxY - oEnvelope.MinY) / tResolutionY + _errorValue);
            }
            ////以下添加对偏移计算的纠正,取最小行列数。
            //int oWidth = oEndCol - oBeginCol;
            //int oHeight = oEndRow - oBeginRow;
            //int tWidth = tEndCol - tBeginCol;
            //int tHeight = tEndRow - tBeginRow;
            //oWidth = tWidth = Math.Min(oWidth, tWidth);
            //oHeight = tHeight = Math.Min(oHeight, tHeight);
            //oEndRow = oBeginRow + oHeight;
            //oEndCol = oBeginCol + oWidth;
            //tEndRow = tBeginRow + tHeight;
            //tEndCol = tBeginCol + tWidth;
            return(true);
        }