@@ -52,7 +52,7 @@ def __init__(
5252            inplace = True ,
5353        )
5454        if  different_crs :
55-             self .img2  =  self .img2 .reproject (crs = different_crs )
55+             self .img2  =  self .img2 .reproject (crs = different_crs ,  resampling = "nearest" )
5656
5757        # To check that use_ref_bounds work - create a img that do not cover the whole extent 
5858        self .img3  =  img .copy ()
@@ -160,6 +160,16 @@ def test_stack_rasters(self, rasters) -> None:  # type: ignore
160160        stacked_img2  =  gu .raster .stack_rasters ([rasters .img1 , rasters .img3 ], reference = rasters .img , use_ref_bounds = True )
161161        assert  stacked_img2 .bounds  ==  rasters .img .bounds 
162162
163+         # This case should preserve unique data values through "nearest" resampling 
164+         rasters .img1 [:] =  5 
165+         rasters .img1 [0 :5 , 0 :5 ] =  1 
166+         rasters .img2  =  rasters .img1 .translate (0.5 , 0.5 , distance_unit = "pixel" )
167+         stacked_img  =  gu .raster .stack_rasters ([rasters .img1 , rasters .img2 ], resampling_method = "nearest" )
168+         assert  np .array_equal (np .unique (stacked_img .data .compressed ()), np .array ([1 , 5 ]))
169+         # But not this case with a shifted raster resampled with "bilinear" 
170+         stacked_img  =  gu .raster .stack_rasters ([rasters .img1 , rasters .img2 ], resampling_method = "bilinear" )
171+         assert  not  np .array_equal (np .unique (stacked_img .data .compressed ()), np .array ([1 , 5 ]))
172+ 
163173    @pytest .mark .parametrize ( 
164174        "rasters" , 
165175        [ 
0 commit comments