Exemplo n.º 1
0
        private const int MAX_BLOCK_SIZE = 1024 * 1024 * 10;//10MB

        public void Compute(IRasterBand[] srcRasters, int[] aoi, RasterQuickStatResult[] results, Action <int, string> progressTracker)
        {
            int       width   = srcRasters[0].Width;
            int       height  = srcRasters[0].Height;
            Rectangle aoiRect = AOIHelper.ComputeAOIRect(aoi, new Size(width, height));
            SortedList <int, AOIHelper.ColRangeOfRow> aoiRowRanges = AOIHelper.ComputeColRanges(aoi, new Size(width, height));

            T[]      buffer    = GetRowBuffer(aoiRowRanges);
            GCHandle handle    = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   bufferPtr = handle.AddrOfPinnedObject();

            try
            {
                int cols = 0;
                for (int i = 0; i < srcRasters.Length; i++)
                {
                    foreach (int r in aoiRowRanges.Keys)
                    {
                        AOIHelper.ColRangeOfRow range = aoiRowRanges[r];
                        cols = range.EndCol - range.BeginCol + 1;
                        srcRasters[i].Read(range.BeginCol, range.Row, cols, 1, bufferPtr, srcRasters[i].DataType, cols, 1);
                        HandleHistogram(buffer, results[i], cols);
                    }
                }
                HandleMeanValues(srcRasters.Length, results, aoi.Length);
            }
            finally
            {
                handle.Free();
            }
        }
Exemplo n.º 2
0
        private void VisitByAOI(int[] aoi, Action <float, float> action, Action <int, string> progressTracker)
        {
            IRasterBand[] srcRasters = new IRasterBand[] { _xBand, _yBand };
            int           width      = _xBand.Width;
            int           height     = _xBand.Height;
            int           bandCount  = 2;
            Rectangle     aoiRect    = AOIHelper.ComputeAOIRect(aoi, new Size(width, height));
            //Dictionary<int, AOIHelper.AOIRowRange> aoiRowRanges = AOIHelper.ComputeRowIndexRange(aoi, new Size(width, height));
            SortedList <int, AOIHelper.ColRangeOfRow> aoiRowRanges = AOIHelper.ComputeColRanges(aoi, new Size(width, height));
            int rowCount = aoiRect.Height;
            int bRow = aoiRect.Top;
            int eRow = aoiRect.Bottom;
            int bCol = 0, eCol = 0;

            T[][]      srcBuffers = new T[bandCount][];
            GCHandle[] srcHandles = new GCHandle[bandCount];
            for (int i = 0; i < bandCount; i++)
            {
                srcBuffers[i] = new T[width];
                srcHandles[i] = GCHandle.Alloc(srcBuffers[i], GCHandleType.Pinned);
            }
            //
            try
            {
                AOIHelper.ColRangeOfRow range = null;
                for (int r = bRow; r < eRow; r++)
                {
                    //读取一行数据
                    for (int b = 0; b < bandCount; b++)
                    {
                        srcRasters[b].Read(0, r, width, 1, srcHandles[b].AddrOfPinnedObject(), _xBand.DataType, width, 1);
                    }
                    //获取该行AOI的起始列
                    if (aoiRowRanges.ContainsKey(r))
                    {
                        range = aoiRowRanges[r];
                    }
                    else
                    {
                        continue;
                    }
                    //调用计算委托
                    bCol = range.BeginCol;
                    eCol = range.EndCol;
                    for (int c = bCol; c < eCol; c++)
                    {
                        action(ToFloat(srcBuffers[0][c]), ToFloat(srcBuffers[1][c]));
                    }
                    //
                    if (progressTracker != null)
                    {
                        progressTracker(100 * (r - bRow + 1) / rowCount, string.Empty);
                    }
                }
            }
            finally
            {
                for (int i = 0; i < bandCount; i++)
                {
                    srcHandles[i].Free();
                }
            }
        }
Exemplo n.º 3
0
        private void ComputeByAOI(IRasterBand[] srcRasters, int[] aoi, out double[] minValues, out double[] maxValues, out double[] meanValues, Action <int, string> progressTracker)
        {
            enumDataType dataType = srcRasters[0].DataType;
            int          width    = srcRasters[0].Width;
            int          height   = srcRasters[0].Height;
            //
            int bandCount = srcRasters.Length;

            minValues  = new double[bandCount];
            maxValues  = new double[bandCount];
            meanValues = new double[bandCount];
            for (int i = 0; i < bandCount; i++)
            {
                minValues[i] = double.MaxValue;
                maxValues[i] = double.MinValue;
            }
            //
            Rectangle aoiRect = AOIHelper.ComputeAOIRect(aoi, new Size(width, height));
            SortedList <int, AOIHelper.ColRangeOfRow> aoiRowRanges = AOIHelper.ComputeColRanges(aoi, new Size(width, height));
            int rowCount = aoiRect.Height;
            int bRow = aoiRect.Top;
            int eRow = aoiRect.Bottom;
            int bCol = 0, eCol = 0;

            T[][]      srcBuffers = new T[bandCount][];
            GCHandle[] srcHandles = new GCHandle[bandCount];
            for (int i = 0; i < bandCount; i++)
            {
                srcBuffers[i] = new T[width];
                srcHandles[i] = GCHandle.Alloc(srcBuffers[i], GCHandleType.Pinned);
            }
            //
            try
            {
                int aoiPixelCount             = 0;
                AOIHelper.ColRangeOfRow range = null;
                for (int r = bRow; r < eRow; r++)
                {
                    try
                    {
                        //读取一行数据
                        for (int b = 0; b < bandCount; b++)
                        {
                            srcRasters[b].Read(0, r, width, 1, srcHandles[b].AddrOfPinnedObject(), dataType, width, 1);
                        }
                        //获取该行AOI的起始列
                        if (aoiRowRanges.ContainsKey(r))
                        {
                            range = aoiRowRanges[r];
                            //调用计算委托
                            bCol = range.BeginCol;
                            eCol = range.EndCol + 1;
                            HandleBlock(bandCount, srcBuffers, bCol, eCol, minValues, maxValues, meanValues);
                            aoiPixelCount += (eCol - bCol);
                            if (progressTracker != null)
                            {
                                progressTracker(100 * (r - bRow + 1) / rowCount, string.Empty);
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        throw ex;
                    }
                }
                HandleMeanValues(bandCount, meanValues, aoiPixelCount);
            }
            finally
            {
                for (int i = 0; i < bandCount; i++)
                {
                    srcHandles[i].Free();
                }
            }
        }