@@ -2347,7 +2347,22 @@ def test_gdalwarp_lib_override_default_output_nodata(frmt, tmp_path):
2347
2347
# Test automatting setting (or not) of SKIP_NOSOURCE=YES
2348
2348
2349
2349
2350
- def test_gdalwarp_lib_auto_skip_nosource (tmp_vsimem ):
2350
+ @pytest .mark .parametrize (
2351
+ "options,checksum" ,
2352
+ [
2353
+ ("-wo SKIP_NOSOURCE=NO" , 41500 ),
2354
+ ("" , 41500 ),
2355
+ ("-wo INIT_DEST=0" , 41500 ),
2356
+ ("-wo INIT_DEST=NO_DATA -dstnodata 0" , 41500 ),
2357
+ ("-dstnodata 0" , 41500 ),
2358
+ ("-dstnodata 1" , 51132 ),
2359
+ ("-dstnodata 1 -wo INIT_DEST=NO_DATA" , 51132 ),
2360
+ ("-dstnodata 1 -wo INIT_DEST=1" , 51132 ),
2361
+ ("-dstnodata 127 -wo INIT_DEST=0" , 41500 ),
2362
+ ],
2363
+ )
2364
+ @pytest .mark .parametrize ("output_format" , ("GTiff" , "MEM" ))
2365
+ def test_gdalwarp_lib_auto_skip_nosource (tmp_vsimem , options , checksum , output_format ):
2351
2366
2352
2367
sr = osr .SpatialReference ()
2353
2368
sr .ImportFromEPSG (4326 )
@@ -2359,80 +2374,20 @@ def test_gdalwarp_lib_auto_skip_nosource(tmp_vsimem):
2359
2374
2360
2375
tmpfilename = tmp_vsimem / "test_gdalwarp_lib_auto_skip_nosource.tif"
2361
2376
2362
- for options in [
2363
- "-wo SKIP_NOSOURCE=NO" ,
2364
- "" ,
2365
- "-wo INIT_DEST=0" ,
2366
- "-wo INIT_DEST=NO_DATA" ,
2367
- "-dstnodata 0" ,
2368
- ]:
2369
- if gdal .VSIStatL (tmpfilename ) is not None :
2370
- gdal .Unlink (tmpfilename )
2371
- out_ds = gdal .Warp (
2372
- tmpfilename ,
2373
- src_ds ,
2374
- options = "-te 1.5 48 3.5 49.5 -wm 100000 " + "-of GTiff " + options ,
2375
- )
2376
- cs = out_ds .GetRasterBand (1 ).Checksum ()
2377
- assert cs == 41500 , (options , cs )
2378
-
2379
- # Same with MEM
2380
- for options in ["" , "-wo INIT_DEST=0" , "-dstnodata 0" ]:
2381
- if gdal .VSIStatL (tmpfilename ) is not None :
2382
- gdal .Unlink (tmpfilename )
2383
- out_ds = gdal .Warp (
2384
- tmpfilename ,
2385
- src_ds ,
2386
- options = "-te 1.5 48 3.5 49.5 -wm 100000 " + "-of MEM " + options ,
2387
- )
2388
- cs = out_ds .GetRasterBand (1 ).Checksum ()
2389
- assert cs == 41500 , (options , cs )
2390
-
2391
- # Use fill/nodata at 1
2392
- for options in [ # '-wo SKIP_NOSOURCE=NO -dstnodata 1',
2393
- "-dstnodata 1" ,
2394
- "-dstnodata 1 -wo INIT_DEST=NO_DATA" ,
2395
- "-dstnodata 1 -wo INIT_DEST=1" ,
2396
- ]:
2397
- if gdal .VSIStatL (tmpfilename ) is not None :
2398
- gdal .Unlink (tmpfilename )
2399
- out_ds = gdal .Warp (
2400
- tmpfilename ,
2401
- src_ds ,
2402
- options = "-te 1.5 48 3.5 49.5 -wm 100000 " + "-of GTiff " + options ,
2403
- )
2404
- cs = out_ds .GetRasterBand (1 ).Checksum ()
2405
- assert cs == 51132 , (options , cs )
2406
-
2407
- # Same with MEM
2408
- for options in [ # '-wo SKIP_NOSOURCE=NO -dstnodata 1',
2409
- "-dstnodata 1" ,
2410
- "-dstnodata 1 -wo INIT_DEST=NO_DATA" ,
2411
- "-dstnodata 1 -wo INIT_DEST=1" ,
2412
- ]:
2413
- if gdal .VSIStatL (tmpfilename ) is not None :
2414
- gdal .Unlink (tmpfilename )
2415
- out_ds = gdal .Warp (
2416
- tmpfilename ,
2417
- src_ds ,
2418
- options = "-te 1.5 48 3.5 49.5 -wm 100000 " + "-of MEM " + options ,
2419
- )
2420
- cs = out_ds .GetRasterBand (1 ).Checksum ()
2421
- assert cs == 51132 , (options , cs )
2422
-
2423
- # Rather dummy: use a INIT_DEST different of the target dstnodata
2424
- for options in [ # '-wo SKIP_NOSOURCE=NO -dstnodata 1 -wo INIT_DEST=0',
2425
- "-dstnodata 127 -wo INIT_DEST=0"
2426
- ]:
2427
- if gdal .VSIStatL (tmpfilename ) is not None :
2428
- gdal .Unlink (tmpfilename )
2429
- out_ds = gdal .Warp (
2430
- tmpfilename ,
2431
- src_ds ,
2432
- options = "-te 1.5 48 3.5 49.5 -wm 100000 " + "-of GTiff " + options ,
2433
- )
2434
- cs = out_ds .GetRasterBand (1 ).Checksum ()
2435
- assert cs == 41500 , (options , cs )
2377
+ out_ds = gdal .Warp (
2378
+ tmpfilename ,
2379
+ src_ds ,
2380
+ options = f"-te 1.5 48 3.5 49.5 -wm 100000 -of { output_format } { options } " ,
2381
+ )
2382
+ cs = out_ds .GetRasterBand (1 ).Checksum ()
2383
+
2384
+ assert cs == checksum , options
2385
+
2386
+
2387
+ def test_gdalwarp_lib_auto_skip_nosource_2 (tmp_vsimem ):
2388
+
2389
+ sr = osr .SpatialReference ()
2390
+ sr .ImportFromEPSG (4326 )
2436
2391
2437
2392
# Test with 2 input datasets
2438
2393
src_ds1 = gdal .GetDriverByName ("MEM" ).Create ("" , 500 , 500 )
@@ -2445,16 +2400,13 @@ def test_gdalwarp_lib_auto_skip_nosource(tmp_vsimem):
2445
2400
src_ds2 .SetGeoTransform ([2.5 , 0.001 , 0 , 49 , 0 , - 0.001 ])
2446
2401
src_ds2 .SetProjection (sr .ExportToWkt ())
2447
2402
2448
- for options in ["" ]:
2449
- if gdal .VSIStatL (tmpfilename ) is not None :
2450
- gdal .Unlink (tmpfilename )
2451
- out_ds = gdal .Warp (
2452
- tmpfilename ,
2453
- [src_ds1 , src_ds2 ],
2454
- options = "-te 1.5 48 3.5 49.5 -wm 100000 " + "-of GTiff " + options ,
2455
- )
2456
- cs = out_ds .GetRasterBand (1 ).Checksum ()
2457
- assert cs == 41500 , (options , cs )
2403
+ out_ds = gdal .Warp (
2404
+ tmp_vsimem / "out.tif" ,
2405
+ [src_ds1 , src_ds2 ],
2406
+ options = "-te 1.5 48 3.5 49.5 -wm 100000 -of GTiff " ,
2407
+ )
2408
+ cs = out_ds .GetRasterBand (1 ).Checksum ()
2409
+ assert cs == 41500
2458
2410
2459
2411
2460
2412
###############################################################################
@@ -4419,3 +4371,28 @@ def test_gdalwarp_lib_cubic_multiband_uint16_4sample_optim():
4419
4371
4689 ,
4420
4372
5007 ,
4421
4373
]
4374
+
4375
+
4376
+ ###############################################################################
4377
+ # Test invalid values of INIT_DEST
4378
+
4379
+
4380
+ def test_gdalwarp_lib_init_dest_invalid (tmp_vsimem ):
4381
+
4382
+ src_ds = gdal .Open ("../gcore/data/byte.tif" )
4383
+
4384
+ with pytest .raises (Exception , match = "Unexpected value of BAND_INIT" ):
4385
+ gdal .Warp (
4386
+ tmp_vsimem / "out.tif" ,
4387
+ src_ds ,
4388
+ outputBounds = (440000 , 3750120 , 441920 , 3751320 ),
4389
+ warpOptions = {"INIT_DEST" : "NODATA" },
4390
+ )
4391
+
4392
+ with pytest .raises (Exception , match = "NoData value was not defined" ):
4393
+ gdal .Warp (
4394
+ tmp_vsimem / "out.tif" ,
4395
+ src_ds ,
4396
+ outputBounds = (440000 , 3750120 , 441920 , 3751320 ),
4397
+ warpOptions = {"INIT_DEST" : "NO_DATA" },
4398
+ )
0 commit comments