/// <summary> /// Asserts the results for the specified band. /// </summary> /// <param name="source">The source raster.</param> /// <param name="sourceBandIndex">The band index of the source raster.</param> /// <param name="result">The resulting raster.</param> /// <param name="resultBandIndex">The band index of the resulting raster.</param> /// <param name="filterRadius">The radius of the filter.</param> private void AssertResultForBand(IRaster source, Int32 sourceBandIndex, IRaster result, Int32 resultBandIndex, Int32 filterRadius) { for (Int32 rowIndex = 0; rowIndex < result.NumberOfRows; rowIndex++) { for (Int32 columnIndex = 0; columnIndex < result.NumberOfColumns; columnIndex++) { Double filteredValue = 0; switch (result.Format) { case RasterFormat.Integer: for (Int32 filterRowIndex = -filterRadius; filterRowIndex <= filterRadius; filterRowIndex++) { for (Int32 filterColumnIndex = -filterRadius; filterColumnIndex <= filterRadius; filterColumnIndex++) { filteredValue += source.GetNearestValue(rowIndex + filterRowIndex, columnIndex + filterColumnIndex, sourceBandIndex); } } filteredValue /= Calculator.Square(2 * filterRadius + 1); Assert.AreEqual(Convert.ToUInt32(filteredValue), result.GetValue(rowIndex, columnIndex, resultBandIndex)); break; case RasterFormat.Floating: for (Int32 filterRowIndex = -filterRadius; filterRowIndex <= filterRadius; filterRowIndex++) { for (Int32 filterColumnIndex = -filterRadius; filterColumnIndex <= filterRadius; filterColumnIndex++) { filteredValue += source.GetNearestFloatValue(rowIndex + filterRowIndex, columnIndex + filterColumnIndex, sourceBandIndex); } } filteredValue /= Calculator.Square(2 * filterRadius + 1); Assert.AreEqual(filteredValue, result.GetFloatValue(rowIndex, columnIndex, resultBandIndex)); break; } } } }
/// <summary> /// Gets the nearest spectral value to a specified row and column index. /// </summary> /// <param name="rowIndex">The zero-based column index of the value.</param> /// <param name="columnIndex">The zero-based row index of the value.</param> /// <returns>The spectral value located at the specified row and column index or in the nearest index if either the row or column indices are out of range.</returns> /// <exception cref="System.NotSupportedException">The raster is not readable.</exception> public UInt32 GetNearestValue(Int32 rowIndex, Int32 columnIndex) { return(_raster.GetNearestValue(rowIndex, columnIndex, _bandIndex)); }