Beispiel #1
0
        public void NearestNeighbourResamplingAlgorithmComputeTest()
        {
            NearestNeighborResamplingAlgorithm strategy = new NearestNeighborResamplingAlgorithm(_rasterMock.Object);

            for (Double rowIndex = 0; rowIndex < _rasterMock.Object.NumberOfRows; rowIndex += 0.1)
            {
                for (Double columnIndex = 0; columnIndex < _rasterMock.Object.NumberOfColumns; columnIndex += 0.1)
                {
                    // individual bands
                    for (Int32 bandIndex = 0; bandIndex < _rasterMock.Object.NumberOfBands; bandIndex++)
                    {
                        Assert.AreEqual(_rasterMock.Object.GetValue(Convert.ToInt32(Math.Floor(rowIndex + 0.5)), Convert.ToInt32(Math.Floor(columnIndex + 0.5)), bandIndex), strategy.Compute(rowIndex, columnIndex, bandIndex));
                    }

                    // all bands
                    Assert.IsTrue(_rasterMock.Object.GetValues(Convert.ToInt32(Math.Floor(rowIndex + 0.5)), Convert.ToInt32(Math.Floor(columnIndex + 0.5))).SequenceEqual(strategy.Compute(rowIndex, columnIndex)));
                }
            }
        }
        public void SpectralResamplingExecuteTest()
        {
            IGeometryFactory factory = new GeometryFactory();

            // integer values

            IDictionary <OperationParameter, Object> parameters = new Dictionary <OperationParameter, Object>();

            parameters.Add(SpectralOperationParameters.RasterResamplingAlgorithmType, typeof(NearestNeighborResamplingAlgorithm));
            parameters.Add(SpectralOperationParameters.NumberOfRows, 20);
            parameters.Add(SpectralOperationParameters.NumberOfColumns, 10);

            SpectralResampling operation = new SpectralResampling(factory.CreateSpectralPolygon(_rasterMock.Object), parameters);

            operation.Execute();


            ISpectralGeometry result = operation.Result;

            Assert.AreEqual(20, result.Raster.NumberOfRows);
            Assert.AreEqual(10, result.Raster.NumberOfColumns);
            Assert.AreEqual(_rasterMock.Object.NumberOfBands, result.Raster.NumberOfBands);
            Assert.AreEqual(_rasterMock.Object.RadiometricResolution, result.Raster.RadiometricResolution);
            Assert.AreEqual(RasterFormat.Integer, result.Raster.Format);

            NearestNeighborResamplingAlgorithm strategy = new NearestNeighborResamplingAlgorithm(_rasterMock.Object);

            for (Int32 bandIndex = 0; bandIndex < result.Raster.NumberOfBands; bandIndex++)
            {
                for (Int32 rowIndex = 0; rowIndex < result.Raster.NumberOfRows; rowIndex++)
                {
                    for (Int32 columnIndex = 0; columnIndex < result.Raster.NumberOfColumns; columnIndex++)
                    {
                        Int32 sourceRowIndex    = (Int32)(Math.Floor((rowIndex + 0.5) * _rasterMock.Object.NumberOfRows / 20));
                        Int32 sourceColumnIndex = (Int32)(Math.Floor((columnIndex + 0.5) * _rasterMock.Object.NumberOfColumns / 10));

                        Assert.AreEqual(_rasterMock.Object.GetValue(sourceRowIndex, sourceColumnIndex, bandIndex), result.Raster.GetValue(rowIndex, columnIndex, bandIndex));
                    }
                }
            }


            // floating point values

            _rasterMock.Setup(raster => raster.Format).Returns(RasterFormat.Floating);

            operation = new SpectralResampling(factory.CreateSpectralPolygon(_rasterMock.Object), parameters);
            operation.Execute();

            result = operation.Result;

            for (Int32 bandIndex = 0; bandIndex < result.Raster.NumberOfBands; bandIndex++)
            {
                for (Int32 rowIndex = 0; rowIndex < result.Raster.NumberOfRows; rowIndex++)
                {
                    for (Int32 columnIndex = 0; columnIndex < result.Raster.NumberOfColumns; columnIndex++)
                    {
                        Int32 sourceRowIndex    = (Int32)(Math.Floor((rowIndex + 0.5) * _rasterMock.Object.NumberOfRows / 20));
                        Int32 sourceColumnIndex = (Int32)(Math.Floor((columnIndex + 0.5) * _rasterMock.Object.NumberOfColumns / 10));

                        Assert.AreEqual(_rasterMock.Object.GetFloatValue(sourceRowIndex, sourceColumnIndex, bandIndex), result.Raster.GetValue(rowIndex, columnIndex, bandIndex));
                    }
                }
            }
        }