@@ -176,53 +176,69 @@ def test_sizes_with_read():
176176def test_sizes_with_part ():
177177 """test automatic width/height calc for reader.part."""
178178 # rectangular shape
179+ # bounds in dataset CRS
179180 bounds = [467258 , 8141872 , 566702 , 8207016 ]
180181 with rasterio .open (COG ) as src_dst :
181182 # full res
182- img = reader .part (src_dst , bounds )
183+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs )
183184 assert img .height == 651
184185 assert img .width == 994
185186
186- img = reader .part (src_dst , bounds , max_size = 100 )
187+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs , max_size = 100 )
187188 assert img .height == 66
188189 assert img .width == 100
189190
190- img = reader .part (src_dst , bounds , width = 100 )
191+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs , width = 100 )
191192 assert img .height == 66
192193 assert img .width == 100
193194
194- img = reader .part (src_dst , bounds , height = 66 )
195+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs , height = 66 )
195196 assert img .height == 66
196197 assert img .width == 101
197198
198- img = reader .part (src_dst , bounds , max_size = 100 , dst_crs = "epsg:4326" )
199- assert img .height == 66
199+ img = reader .part (
200+ src_dst , bounds , bounds_crs = src_dst .crs , max_size = 100 , dst_crs = "epsg:4326"
201+ )
202+ assert img .height == 19
200203 assert img .width == 100
201204
202- img = reader .part (src_dst , bounds , width = 100 , dst_crs = "epsg:4326" )
203- assert img .height == 66
205+ img = reader .part (
206+ src_dst , bounds , bounds_crs = src_dst .crs , width = 100 , dst_crs = "epsg:4326"
207+ )
208+ assert img .height == 19
204209 assert img .width == 100
205210
206- img = reader .part (src_dst , bounds , height = 66 , dst_crs = "epsg:4326" )
207- assert img .height == 66
208- assert img .width == 101
211+ img = reader .part (
212+ src_dst , bounds , bounds_crs = src_dst .crs , height = 19 , dst_crs = "epsg:4326"
213+ )
214+ assert img .height == 19
215+ assert img .width == 104
209216
210217
211218def test_resampling_returns_different_results ():
212219 """Make sure resampling works."""
220+ # bounds in EPSG:3857
213221 bounds = [
214222 - 6574807.42497772 ,
215223 12210356.646387195 ,
216224 - 6261721.357121638 ,
217225 12523442.714243278 ,
218226 ]
219227 with rasterio .open (COG ) as src_dst :
220- arr , _ = reader .part (src_dst , bounds , 64 , 64 , dst_crs = constants .WEB_MERCATOR_CRS )
228+ arr , _ = reader .part (
229+ src_dst ,
230+ bounds ,
231+ 64 ,
232+ 64 ,
233+ bounds_crs = constants .WEB_MERCATOR_CRS ,
234+ dst_crs = constants .WEB_MERCATOR_CRS ,
235+ )
221236 arr2 , _ = reader .part (
222237 src_dst ,
223238 bounds ,
224239 64 ,
225240 64 ,
241+ bounds_crs = constants .WEB_MERCATOR_CRS ,
226242 dst_crs = constants .WEB_MERCATOR_CRS ,
227243 resampling_method = "bilinear" ,
228244 )
@@ -231,6 +247,7 @@ def test_resampling_returns_different_results():
231247
232248def test_resampling_with_diff_padding_returns_different_results ():
233249 """Test result is different with different padding."""
250+ # bounds in EPSG:3857
234251 bounds = [
235252 - 6574807.42497772 ,
236253 12210356.646387195 ,
@@ -279,6 +296,7 @@ def test_resampling_with_diff_padding_returns_different_results():
279296
280297def test_tile_read_invalidResampling ():
281298 """Should raise an error on invalid resampling method name."""
299+ # bounds in EPSG:3857
282300 bounds = [
283301 - 6574807.42497772 ,
284302 12210356.646387195 ,
@@ -287,35 +305,38 @@ def test_tile_read_invalidResampling():
287305 ]
288306 with pytest .raises (KeyError ):
289307 with rasterio .open (COG ) as src_dst :
290- reader .part (src_dst , bounds , 16 , 16 , resampling_method = "jacques" )
308+ reader .part (
309+ src_dst ,
310+ bounds ,
311+ 16 ,
312+ 16 ,
313+ resampling_method = "jacques" ,
314+ bounds_crs = constants .WEB_MERCATOR_CRS ,
315+ dst_crs = constants .WEB_MERCATOR_CRS ,
316+ )
291317
292318
293- def test_tile_read_tuple_index ():
319+ def test_tile_read_index ():
294320 """Should work as expected"""
321+ # bounds in EPSG:3857
295322 bounds = (
296323 - 11663507.036777973 ,
297324 4715018.0897710975 ,
298325 - 11663487.927520901 ,
299326 4715037.199028169 ,
300327 )
301328 with rasterio .open (S3_PATH ) as src_dst :
302- arr , mask = reader .part (src_dst , bounds , 16 , 16 , indexes = (1 ,))
303- assert arr .shape == (1 , 16 , 16 )
304- assert mask .shape == (16 , 16 )
305-
329+ arr , mask = reader .part (
330+ src_dst , bounds , 16 , 16 , indexes = (1 ,), bounds_crs = constants .WEB_MERCATOR_CRS
331+ )
332+ assert arr .shape == (1 , 16 , 16 )
333+ assert mask .shape == (16 , 16 )
306334
307- def test_tile_read_int_index ():
308- """Should work as expected."""
309- bounds = (
310- - 11663507.036777973 ,
311- 4715018.0897710975 ,
312- - 11663487.927520901 ,
313- 4715037.199028169 ,
314- )
315- with rasterio .open (S3_PATH ) as src_dst :
316- arr , mask = reader .part (src_dst , bounds , 16 , 16 , indexes = 1 )
317- assert arr .shape == (1 , 16 , 16 )
318- assert mask .shape == (16 , 16 )
335+ arr , mask = reader .part (
336+ src_dst , bounds , 16 , 16 , indexes = 1 , bounds_crs = constants .WEB_MERCATOR_CRS
337+ )
338+ assert arr .shape == (1 , 16 , 16 )
339+ assert mask .shape == (16 , 16 )
319340
320341
321342def test_tile_read_bgr ():
@@ -327,7 +348,14 @@ def test_tile_read_bgr():
327348 4715037.199028169 ,
328349 )
329350 with rasterio .open (S3_PATH ) as src_dst :
330- arr , mask = reader .part (src_dst , bounds , 16 , 16 , indexes = (3 , 2 , 1 ))
351+ arr , mask = reader .part (
352+ src_dst ,
353+ bounds ,
354+ 16 ,
355+ 16 ,
356+ indexes = (3 , 2 , 1 ),
357+ bounds_crs = constants .WEB_MERCATOR_CRS ,
358+ )
331359 assert arr .shape == (3 , 16 , 16 )
332360 assert mask .shape == (16 , 16 )
333361
@@ -343,7 +371,14 @@ def test_tile_read_nodata():
343371 ]
344372 tilesize = 16
345373 with rasterio .open (COG ) as src_dst :
346- arr , mask = reader .part (src_dst , bounds , tilesize , tilesize , nodata = 1 )
374+ arr , mask = reader .part (
375+ src_dst ,
376+ bounds ,
377+ tilesize ,
378+ tilesize ,
379+ nodata = 1 ,
380+ bounds_crs = constants .WEB_MERCATOR_CRS ,
381+ )
347382 assert arr .shape == (1 , 16 , 16 )
348383 assert mask .shape == (16 , 16 )
349384 assert not mask .all ()
@@ -360,7 +395,14 @@ def test_tile_read_nodata_and_alpha():
360395
361396 tilesize = 16
362397 with rasterio .open (PIX4D_PATH ) as src_dst :
363- arr , mask = reader .part (src_dst , bounds , tilesize , tilesize , indexes = [1 , 2 , 3 ])
398+ arr , mask = reader .part (
399+ src_dst ,
400+ bounds ,
401+ tilesize ,
402+ tilesize ,
403+ indexes = [1 , 2 , 3 ],
404+ bounds_crs = constants .WEB_MERCATOR_CRS ,
405+ )
364406 assert arr .shape == (3 , 16 , 16 )
365407 assert mask .shape == (16 , 16 )
366408 assert not mask .all ()
@@ -377,7 +419,9 @@ def test_tile_read_dataset_nodata():
377419 )
378420 tilesize = 16
379421 with rasterio .open (S3_NODATA_PATH ) as src_dst :
380- arr , mask = reader .part (src_dst , bounds , tilesize , tilesize )
422+ arr , mask = reader .part (
423+ src_dst , bounds , tilesize , tilesize , bounds_crs = constants .WEB_MERCATOR_CRS
424+ )
381425 assert arr .shape == (3 , 16 , 16 )
382426 assert not mask .all ()
383427
@@ -393,7 +437,14 @@ def test_tile_read_not_covering_the_whole_tile():
393437 tilesize = 16
394438 with pytest .raises (TileOutsideBounds ):
395439 with rasterio .open (COG ) as src_dst :
396- reader .part (src_dst , bounds , tilesize , tilesize , minimum_overlap = 0.6 )
440+ reader .part (
441+ src_dst ,
442+ bounds ,
443+ tilesize ,
444+ tilesize ,
445+ minimum_overlap = 0.6 ,
446+ bounds_crs = constants .WEB_MERCATOR_CRS ,
447+ )
397448
398449
399450# See https://github.com/cogeotiff/rio-tiler/issues/105#issuecomment-492268836
@@ -408,7 +459,14 @@ def test_tile_read_validMask():
408459 ]
409460 tilesize = 128
410461 with rasterio .open (COG ) as src_dst :
411- arr , mask = reader .part (src_dst , bounds , tilesize , tilesize , nodata = 1 )
462+ arr , mask = reader .part (
463+ src_dst ,
464+ bounds ,
465+ tilesize ,
466+ tilesize ,
467+ nodata = 1 ,
468+ bounds_crs = constants .WEB_MERCATOR_CRS ,
469+ )
412470
413471 masknodata = (arr [0 ] != 1 ).astype (numpy .uint8 ) * 255
414472 numpy .testing .assert_array_equal (mask , masknodata )
@@ -423,7 +481,7 @@ def test_read_nodata():
423481 8148789 ,
424482 ]
425483 with rasterio .open (COG ) as src_dst :
426- arr , mask = reader .part (src_dst , bounds , nodata = 1 )
484+ arr , mask = reader .part (src_dst , bounds , nodata = 1 , bounds_crs = src_dst . crs )
427485
428486 masknodata = (arr [0 ] != 1 ).astype (numpy .uint16 ) * 65535
429487 numpy .testing .assert_array_equal (mask , masknodata )
@@ -443,6 +501,7 @@ def test_read_nodata():
443501
444502def test_tile_read_crs ():
445503 """Read tile using different target CRS and bounds CRS."""
504+ # Bounds in epsg:3857
446505 bounds = (
447506 - 11663507.036777973 ,
448507 4715018.0897710975 ,
@@ -465,6 +524,7 @@ def test_tile_read_crs():
465524 assert mask .shape == (16 , 16 )
466525
467526 # Test target CRS with input bounds in target CRS
527+ # bounds in epsg:4326
468528 bounds = (
469529 - 104.7750663757324 ,
470530 38.95353532141203 ,
@@ -499,6 +559,7 @@ def test_tile_read_vrt_option():
499559 tilesize ,
500560 tilesize ,
501561 vrt_options = {"source_extra" : 10 , "num_threads" : 10 },
562+ bounds_crs = constants .WEB_MERCATOR_CRS ,
502563 )
503564 assert arr .shape == (1 , 16 , 16 )
504565 assert mask .shape == (16 , 16 )
@@ -621,6 +682,7 @@ def test_point():
621682
622683def test_part_with_buffer ():
623684 """Make sure buffer works as expected."""
685+ # Bounds in EPSG:3857
624686 bounds = [
625687 - 6574807.42497772 ,
626688 12210356.646387195 ,
@@ -629,7 +691,12 @@ def test_part_with_buffer():
629691 ]
630692 # Read part at full resolution
631693 with rasterio .open (COG ) as src_dst :
632- img_no_buffer = reader .part (src_dst , bounds , dst_crs = constants .WEB_MERCATOR_CRS )
694+ img_no_buffer = reader .part (
695+ src_dst ,
696+ bounds ,
697+ dst_crs = constants .WEB_MERCATOR_CRS ,
698+ bounds_crs = constants .WEB_MERCATOR_CRS ,
699+ )
633700
634701 x_size = img_no_buffer .width
635702 y_size = img_no_buffer .height
@@ -654,12 +721,19 @@ def test_part_with_buffer():
654721 height = ny ,
655722 width = nx ,
656723 dst_crs = constants .WEB_MERCATOR_CRS ,
724+ bounds_crs = constants .WEB_MERCATOR_CRS ,
657725 )
658726 assert img .width == nx
659727 assert img .height == ny
660728
661729 with rasterio .open (COG ) as src_dst :
662- imgb = reader .part (src_dst , bounds , buffer = 2 , dst_crs = constants .WEB_MERCATOR_CRS )
730+ imgb = reader .part (
731+ src_dst ,
732+ bounds ,
733+ buffer = 2 ,
734+ dst_crs = constants .WEB_MERCATOR_CRS ,
735+ bounds_crs = constants .WEB_MERCATOR_CRS ,
736+ )
663737 assert imgb .width == nx
664738 assert imgb .height == ny
665739
@@ -685,6 +759,7 @@ def test_part_with_buffer_overzoom():
685759 img_no_buffer = reader .part (
686760 src_dst ,
687761 bounds ,
762+ bounds_crs = constants .WEB_MERCATOR_CRS ,
688763 dst_crs = constants .WEB_MERCATOR_CRS ,
689764 height = 2000 ,
690765 width = 2000 ,
@@ -712,6 +787,7 @@ def test_part_with_buffer_overzoom():
712787 bounds_with_buffer ,
713788 height = ny ,
714789 width = nx ,
790+ bounds_crs = constants .WEB_MERCATOR_CRS ,
715791 dst_crs = constants .WEB_MERCATOR_CRS ,
716792 )
717793 assert img .width == nx
@@ -722,6 +798,7 @@ def test_part_with_buffer_overzoom():
722798 src_dst ,
723799 bounds ,
724800 buffer = 2 ,
801+ bounds_crs = constants .WEB_MERCATOR_CRS ,
725802 dst_crs = constants .WEB_MERCATOR_CRS ,
726803 height = 2000 ,
727804 width = 2000 ,
@@ -852,7 +929,7 @@ def test_part_no_VRT():
852929 assert img .bounds == bounds_dst_crs
853930
854931 # Use bbox in Image CRS
855- img_crs = reader .part (src_dst , bounds_dst_crs )
932+ img_crs = reader .part (src_dst , bounds_dst_crs , bounds_crs = src_dst . crs )
856933 assert img .height == 1453
857934 assert img .width == 1613
858935 assert img_crs .mask [0 , 0 ] == 65535
0 commit comments