|
19 | 19 | package org.apache.sedona.common.raster; |
20 | 20 |
|
21 | 21 | import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertFalse; |
22 | 23 | import static org.junit.Assert.assertThrows; |
23 | 24 |
|
24 | 25 | import java.awt.image.DataBuffer; |
@@ -3577,6 +3578,39 @@ public void testInterpolate() throws FactoryException { |
3577 | 3578 | assertEquals(0.0, RasterUtils.getNoDataValue(modifiedRaster6.getSampleDimension(1)), 0.01d); |
3578 | 3579 | } |
3579 | 3580 |
|
| 3581 | + /** |
| 3582 | + * Test that when interpolating a single band in a multi-band raster, the other bands are |
| 3583 | + * preserved unchanged. |
| 3584 | + */ |
| 3585 | + @Test |
| 3586 | + public void testInterpolatePreservesOtherBands() throws FactoryException { |
| 3587 | + double[] band1Values = |
| 3588 | + new double[] {1, Double.NaN, 3, Double.NaN, 5, Double.NaN, 7, Double.NaN, 9}; |
| 3589 | + double[] band2Values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 3590 | + |
| 3591 | + GridCoverage2D raster = RasterConstructors.makeEmptyRaster(2, 3, 3, 0, 0, 1); |
| 3592 | + // Use -9999 as noDataValue so 0 is preserved as a valid value |
| 3593 | + raster = MapAlgebra.addBandFromArray(raster, band1Values, 1, -9999.0); |
| 3594 | + raster = MapAlgebra.addBandFromArray(raster, band2Values, 2, -9999.0); |
| 3595 | + |
| 3596 | + // Interpolate only band 1 (specify band=1), leaving band 2 unchanged |
| 3597 | + GridCoverage2D result = RasterEditors.interpolate(raster, 2.0, "Fixed", 3.0, 1.0, 1); |
| 3598 | + |
| 3599 | + // Verify band 1 was interpolated (NaN values should be filled) |
| 3600 | + double[] resultBand1 = MapAlgebra.bandAsArray(result, 1); |
| 3601 | + for (int i = 0; i < resultBand1.length; i++) { |
| 3602 | + // Band 1 should not have any NaN values after interpolation |
| 3603 | + assertFalse("Band 1 should not have NaN at index " + i, Double.isNaN(resultBand1[i])); |
| 3604 | + } |
| 3605 | + |
| 3606 | + // Verify band 2 is EXACTLY the same as original |
| 3607 | + double[] resultBand2 = MapAlgebra.bandAsArray(result, 2); |
| 3608 | + assertEquals( |
| 3609 | + "Band 2 should be preserved unchanged", |
| 3610 | + Arrays.toString(band2Values), |
| 3611 | + Arrays.toString(resultBand2)); |
| 3612 | + } |
| 3613 | + |
3580 | 3614 | @Test |
3581 | 3615 | public void testResample() throws FactoryException, TransformException { |
3582 | 3616 | double[] values = {1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10}; |
|
0 commit comments