Beispiel #1
0
        /// <summary>
        /// Run an operation over every cell individually
        /// </summary>
        public void Run()
        {
            List <T[]> data = new List <T[]>(_inputRasters.Count);

            StateChange(OpStatus.States.Started);

            // Set up an array with nodatavals to be populated (or not)
            for (int idx = 0; idx < _inputRasters.Count; idx++)
            {
                data.Add(new T[ChunkExtent.Cols * ChunkExtent.Rows]);
            }

            List <T[]> outBuffer = new List <T[]>();

            foreach (Raster outraster in _outputRasters)
            {
                outBuffer.Add(new T[ChunkExtent.Cols * ChunkExtent.Rows]);
            }

            while (!OpDone)
            {
                GetChunk(data);
                ProgressChange(Progress);
#if DEBUG
                tmr_calculations.Start();
                num_writes++;
#endif
                ChunkOp(data, outBuffer);
#if DEBUG
                tmr_calculations.Stop();
#endif

                for (int idx = 0; idx < _outputRasters.Count; idx++)
                {
                    // Get the (col,row) offsets
                    int[] offset = ChunkExtent.GetTopCornerTranslationRowCol(OpExtent);
                    // Write this window tot he file
                    // it goes (colNum, rowNum, COLS, ROWS, buffer);
#if DEBUG
                    tmr_rasterwrite.Start();
#endif
                    _outputRasters[idx].Write(offset[1], offset[0] + _vOffset, ChunkExtent.Cols, ChunkExtent.Rows, outBuffer[idx]);
#if DEBUG
                    tmr_rasterwrite.Stop();
#endif
                }
                // We always increment to the next one
                NextChunk();
            }
            ProgressChange(100);
            StateChange(OpStatus.States.Complete);

            Cleanup();
        }
Beispiel #2
0
        /// <summary>
        /// Get a number of chunks from the actual rasters
        /// NOTE: for now a chunk goes across the whole extent to make the math easier
        /// </summary>
        /// <returns></returns>
        public void GetChunk(List <T[]> data)
        {
            for (int idx = 0; idx < _inputRasters.Count; idx++)
            {
                Raster rRa = _inputRasters[idx];

                // Reset everything first so we don't get any data bleed
                // NOTE: if this is slow we can revisit
                data[idx].Fill(inNodataVals[idx]);

                ExtentRectangle _interSectRect = rRa.Extent.Intersect(ChunkExtent);

                // Make sure there's some data to read, otherwise return the filled nodata values from above
                if (_interSectRect.Rows > 0 && _interSectRect.Cols > 0)
                {
                    T[] _buffer = new T[_interSectRect.Rows * _interSectRect.Cols];

                    // Find the offset between the intersection and rRa
                    int[] offrRa = _interSectRect.GetTopCornerTranslationRowCol(rRa.Extent);
#if DEBUG
                    tmr_rasterread.Start();
                    num_reads++;
#endif
                    _inputRasters[idx].Read(offrRa[1], offrRa[0], _interSectRect.Cols, _interSectRect.Rows, _buffer);
#if DEBUG
                    tmr_rasterread.Stop();
#endif

                    // Find the offset between the intersection and the chunkwindow
                    int[] offChunk = _interSectRect.GetTopCornerTranslationRowCol(ChunkExtent);
                    data[idx].Plunk(_buffer,
                                    ChunkExtent.Rows, ChunkExtent.Cols,
                                    _interSectRect.Rows, _interSectRect.Cols,
                                    offChunk[0], offChunk[1]);
                }
            }
        }