@@ -176,53 +176,69 @@ def test_sizes_with_read():
176
176
def test_sizes_with_part ():
177
177
"""test automatic width/height calc for reader.part."""
178
178
# rectangular shape
179
+ # bounds in dataset CRS
179
180
bounds = [467258 , 8141872 , 566702 , 8207016 ]
180
181
with rasterio .open (COG ) as src_dst :
181
182
# full res
182
- img = reader .part (src_dst , bounds )
183
+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs )
183
184
assert img .height == 651
184
185
assert img .width == 994
185
186
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 )
187
188
assert img .height == 66
188
189
assert img .width == 100
189
190
190
- img = reader .part (src_dst , bounds , width = 100 )
191
+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs , width = 100 )
191
192
assert img .height == 66
192
193
assert img .width == 100
193
194
194
- img = reader .part (src_dst , bounds , height = 66 )
195
+ img = reader .part (src_dst , bounds , bounds_crs = src_dst . crs , height = 66 )
195
196
assert img .height == 66
196
197
assert img .width == 101
197
198
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
200
203
assert img .width == 100
201
204
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
204
209
assert img .width == 100
205
210
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
209
216
210
217
211
218
def test_resampling_returns_different_results ():
212
219
"""Make sure resampling works."""
220
+ # bounds in EPSG:3857
213
221
bounds = [
214
222
- 6574807.42497772 ,
215
223
12210356.646387195 ,
216
224
- 6261721.357121638 ,
217
225
12523442.714243278 ,
218
226
]
219
227
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
+ )
221
236
arr2 , _ = reader .part (
222
237
src_dst ,
223
238
bounds ,
224
239
64 ,
225
240
64 ,
241
+ bounds_crs = constants .WEB_MERCATOR_CRS ,
226
242
dst_crs = constants .WEB_MERCATOR_CRS ,
227
243
resampling_method = "bilinear" ,
228
244
)
@@ -231,6 +247,7 @@ def test_resampling_returns_different_results():
231
247
232
248
def test_resampling_with_diff_padding_returns_different_results ():
233
249
"""Test result is different with different padding."""
250
+ # bounds in EPSG:3857
234
251
bounds = [
235
252
- 6574807.42497772 ,
236
253
12210356.646387195 ,
@@ -279,6 +296,7 @@ def test_resampling_with_diff_padding_returns_different_results():
279
296
280
297
def test_tile_read_invalidResampling ():
281
298
"""Should raise an error on invalid resampling method name."""
299
+ # bounds in EPSG:3857
282
300
bounds = [
283
301
- 6574807.42497772 ,
284
302
12210356.646387195 ,
@@ -287,35 +305,38 @@ def test_tile_read_invalidResampling():
287
305
]
288
306
with pytest .raises (KeyError ):
289
307
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
+ )
291
317
292
318
293
- def test_tile_read_tuple_index ():
319
+ def test_tile_read_index ():
294
320
"""Should work as expected"""
321
+ # bounds in EPSG:3857
295
322
bounds = (
296
323
- 11663507.036777973 ,
297
324
4715018.0897710975 ,
298
325
- 11663487.927520901 ,
299
326
4715037.199028169 ,
300
327
)
301
328
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 )
306
334
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 )
319
340
320
341
321
342
def test_tile_read_bgr ():
@@ -327,7 +348,14 @@ def test_tile_read_bgr():
327
348
4715037.199028169 ,
328
349
)
329
350
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
+ )
331
359
assert arr .shape == (3 , 16 , 16 )
332
360
assert mask .shape == (16 , 16 )
333
361
@@ -343,7 +371,14 @@ def test_tile_read_nodata():
343
371
]
344
372
tilesize = 16
345
373
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
+ )
347
382
assert arr .shape == (1 , 16 , 16 )
348
383
assert mask .shape == (16 , 16 )
349
384
assert not mask .all ()
@@ -360,7 +395,14 @@ def test_tile_read_nodata_and_alpha():
360
395
361
396
tilesize = 16
362
397
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
+ )
364
406
assert arr .shape == (3 , 16 , 16 )
365
407
assert mask .shape == (16 , 16 )
366
408
assert not mask .all ()
@@ -377,7 +419,9 @@ def test_tile_read_dataset_nodata():
377
419
)
378
420
tilesize = 16
379
421
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
+ )
381
425
assert arr .shape == (3 , 16 , 16 )
382
426
assert not mask .all ()
383
427
@@ -393,7 +437,14 @@ def test_tile_read_not_covering_the_whole_tile():
393
437
tilesize = 16
394
438
with pytest .raises (TileOutsideBounds ):
395
439
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
+ )
397
448
398
449
399
450
# See https://github.com/cogeotiff/rio-tiler/issues/105#issuecomment-492268836
@@ -408,9 +459,16 @@ def test_tile_read_validMask():
408
459
]
409
460
tilesize = 128
410
461
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
+ )
412
470
413
- masknodata = (arr [0 ] != 1 ).astype (numpy .uint8 ) * 255
471
+ masknodata = (arr [0 ] != 1 ).astype (numpy .uint16 ) * 65535
414
472
numpy .testing .assert_array_equal (mask , masknodata )
415
473
416
474
@@ -423,7 +481,7 @@ def test_read_nodata():
423
481
8148789 ,
424
482
]
425
483
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 )
427
485
428
486
masknodata = (arr [0 ] != 1 ).astype (numpy .uint16 ) * 65535
429
487
numpy .testing .assert_array_equal (mask , masknodata )
@@ -443,6 +501,7 @@ def test_read_nodata():
443
501
444
502
def test_tile_read_crs ():
445
503
"""Read tile using different target CRS and bounds CRS."""
504
+ # Bounds in epsg:3857
446
505
bounds = (
447
506
- 11663507.036777973 ,
448
507
4715018.0897710975 ,
@@ -465,6 +524,7 @@ def test_tile_read_crs():
465
524
assert mask .shape == (16 , 16 )
466
525
467
526
# Test target CRS with input bounds in target CRS
527
+ # bounds in epsg:4326
468
528
bounds = (
469
529
- 104.7750663757324 ,
470
530
38.95353532141203 ,
@@ -499,6 +559,7 @@ def test_tile_read_vrt_option():
499
559
tilesize ,
500
560
tilesize ,
501
561
vrt_options = {"source_extra" : 10 , "num_threads" : 10 },
562
+ bounds_crs = constants .WEB_MERCATOR_CRS ,
502
563
)
503
564
assert arr .shape == (1 , 16 , 16 )
504
565
assert mask .shape == (16 , 16 )
@@ -621,6 +682,7 @@ def test_point():
621
682
622
683
def test_part_with_buffer ():
623
684
"""Make sure buffer works as expected."""
685
+ # Bounds in EPSG:3857
624
686
bounds = [
625
687
- 6574807.42497772 ,
626
688
12210356.646387195 ,
@@ -629,7 +691,12 @@ def test_part_with_buffer():
629
691
]
630
692
# Read part at full resolution
631
693
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
+ )
633
700
634
701
x_size = img_no_buffer .width
635
702
y_size = img_no_buffer .height
@@ -654,12 +721,19 @@ def test_part_with_buffer():
654
721
height = ny ,
655
722
width = nx ,
656
723
dst_crs = constants .WEB_MERCATOR_CRS ,
724
+ bounds_crs = constants .WEB_MERCATOR_CRS ,
657
725
)
658
726
assert img .width == nx
659
727
assert img .height == ny
660
728
661
729
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
+ )
663
737
assert imgb .width == nx
664
738
assert imgb .height == ny
665
739
@@ -685,6 +759,7 @@ def test_part_with_buffer_overzoom():
685
759
img_no_buffer = reader .part (
686
760
src_dst ,
687
761
bounds ,
762
+ bounds_crs = constants .WEB_MERCATOR_CRS ,
688
763
dst_crs = constants .WEB_MERCATOR_CRS ,
689
764
height = 2000 ,
690
765
width = 2000 ,
@@ -712,6 +787,7 @@ def test_part_with_buffer_overzoom():
712
787
bounds_with_buffer ,
713
788
height = ny ,
714
789
width = nx ,
790
+ bounds_crs = constants .WEB_MERCATOR_CRS ,
715
791
dst_crs = constants .WEB_MERCATOR_CRS ,
716
792
)
717
793
assert img .width == nx
@@ -722,6 +798,7 @@ def test_part_with_buffer_overzoom():
722
798
src_dst ,
723
799
bounds ,
724
800
buffer = 2 ,
801
+ bounds_crs = constants .WEB_MERCATOR_CRS ,
725
802
dst_crs = constants .WEB_MERCATOR_CRS ,
726
803
height = 2000 ,
727
804
width = 2000 ,
@@ -852,7 +929,7 @@ def test_part_no_VRT():
852
929
assert img .bounds == bounds_dst_crs
853
930
854
931
# 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 )
856
933
assert img .height == 1453
857
934
assert img .width == 1613
858
935
assert img_crs .mask [0 , 0 ] == 65535
0 commit comments