def test_nearblack_8():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    src_ds = gdal.Open('../gdrivers/data/rgbsmall.tif')
    gdal.GetDriverByName('GTiff').CreateCopy('tmp/nearblack8.tif', src_ds)
    src_ds = None

    (ret, err) = gdaltest.runexternal_out_and_err(
        test_cli_utilities.get_nearblack_path() + ' tmp/nearblack8.tif -nb 0')
    if not (err is None or err == ''):
        gdaltest.post_reason('got error/warning')
        print(err)
        return 'fail'

    ds = gdal.Open('tmp/nearblack8.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 21106:
        print(ds.GetRasterBand(1).Checksum())
        gdaltest.post_reason('Bad checksum band 1')
        return 'fail'

    if ds.GetRasterBand(2).Checksum() != 20736:
        print(ds.GetRasterBand(2).Checksum())
        gdaltest.post_reason('Bad checksum band 2')
        return 'fail'

    if ds.GetRasterBand(3).Checksum() != 21309:
        print(ds.GetRasterBand(3).Checksum())
        gdaltest.post_reason('Bad checksum band 3')
        return 'fail'

    return 'success'
Exemplo n.º 2
0
def test_nearblack_1():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    (_, err) = gdaltest.runexternal_out_and_err(
        test_cli_utilities.get_nearblack_path() +
        ' ../gdrivers/data/rgbsmall.tif -nb 0 -of GTiff -o tmp/nearblack1.tif')
    assert (err is None or err == ''), 'got error/warning'

    src_ds = gdal.Open('../gdrivers/data/rgbsmall.tif')
    ds = gdal.Open('tmp/nearblack1.tif')
    assert ds is not None

    assert ds.GetRasterBand(1).Checksum() == 21106, 'Bad checksum band 1'

    assert ds.GetRasterBand(2).Checksum() == 20736, 'Bad checksum band 2'

    assert ds.GetRasterBand(3).Checksum() == 21309, 'Bad checksum band 3'

    src_gt = src_ds.GetGeoTransform()
    dst_gt = ds.GetGeoTransform()
    for i in range(6):
        assert abs(src_gt[i] - dst_gt[i]) <= 1e-10, 'Bad geotransform'

    dst_wkt = ds.GetProjectionRef()
    assert dst_wkt.find('AUTHORITY["EPSG","4326"]') != -1, 'Bad projection'

    src_ds = None
    ds = None
def test_nearblack_4():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'
    if test_cli_utilities.get_gdalwarp_path() is None:
        return 'skip'

    gdaltest.runexternal(
        test_cli_utilities.get_gdalwarp_path() +
        ' -wo "INIT_DEST=255" ../gdrivers/data/rgbsmall.tif  tmp/nearblack4_src.tif -srcnodata 0'
    )
    gdaltest.runexternal(
        test_cli_utilities.get_nearblack_path() +
        ' -q -setalpha -white -nb 0 -of GTiff tmp/nearblack4_src.tif -o tmp/nearblack4.tif'
    )

    ds = gdal.Open('tmp/nearblack4.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(4).Checksum() != 24151:
        print(ds.GetRasterBand(4).Checksum())
        gdaltest.post_reason('Bad checksum band 0')
        return 'fail'

    ds = None

    return 'success'
def test_nearblack_7():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    gdaltest.runexternal(
        test_cli_utilities.get_nearblack_path() +
        ' data/whiteblackred.tif -o tmp/nearblack7.tif -color 0,0,0 -color 255,255,255 -of GTiff'
    )

    ds = gdal.Open('tmp/nearblack7.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 418 or \
       ds.GetRasterBand(2).Checksum() != 0 or \
       ds.GetRasterBand(3).Checksum() != 0 :
        print(ds.GetRasterBand(1).Checksum())
        print(ds.GetRasterBand(2).Checksum())
        print(ds.GetRasterBand(3).Checksum())
        gdaltest.post_reason('Bad checksum')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 5
0
def test_nearblack_8():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    src_ds = gdal.Open('../gdrivers/data/rgbsmall.tif')
    gdal.GetDriverByName('GTiff').CreateCopy('tmp/nearblack8.tif', src_ds)
    src_ds = None

    (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_nearblack_path() + ' tmp/nearblack8.tif -nb 0')
    if not (err is None or err == ''):
        gdaltest.post_reason('got error/warning')
        print(err)
        return 'fail'

    ds = gdal.Open('tmp/nearblack8.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 21106:
        print(ds.GetRasterBand(1).Checksum())
        gdaltest.post_reason('Bad checksum band 1')
        return 'fail'

    if ds.GetRasterBand(2).Checksum() != 20736:
        print(ds.GetRasterBand(2).Checksum())
        gdaltest.post_reason('Bad checksum band 2')
        return 'fail'

    if ds.GetRasterBand(3).Checksum() != 21309:
        print(ds.GetRasterBand(3).Checksum())
        gdaltest.post_reason('Bad checksum band 3')
        return 'fail'

    return 'success'
Exemplo n.º 6
0
def test_nearblack_2():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif -setalpha -nb 0 -of GTiff -o tmp/nearblack2.tif -co TILED=YES')

    ds = gdal.Open('tmp/nearblack2.tif')
    assert ds is not None

    assert ds.GetRasterBand(4).Checksum() == 22002, 'Bad checksum band 0'

    ds = None
Exemplo n.º 7
0
def test_nearblack_3():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    shutil.copy('tmp/nearblack2.tif', 'tmp/nearblack3.tif')
    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -setalpha -nb 0 -of GTiff tmp/nearblack3.tif')

    ds = gdal.Open('tmp/nearblack3.tif')
    assert ds is not None

    assert ds.GetRasterBand(4).Checksum() == 22002, 'Bad checksum band 0'

    ds = None
Exemplo n.º 8
0
def test_nearblack_5():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif --config GDAL_TIFF_INTERNAL_MASK NO -setmask -nb 0 -of GTiff -o tmp/nearblack5.tif -co TILED=YES')

    ds = gdal.Open('tmp/nearblack5.tif')
    assert ds is not None

    assert ds.GetRasterBand(1).GetMaskBand().Checksum() == 22002, \
        'Bad checksum mask band'

    ds = None
Exemplo n.º 9
0
def test_nearblack_7():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' data/whiteblackred.tif -o tmp/nearblack7.tif -color 0,0,0 -color 255,255,255 -of GTiff')

    ds = gdal.Open('tmp/nearblack7.tif')
    assert ds is not None

    assert (ds.GetRasterBand(1).Checksum() == 418 and \
       ds.GetRasterBand(2).Checksum() == 0 and \
       ds.GetRasterBand(3).Checksum() == 0), 'Bad checksum'

    ds = None
Exemplo n.º 10
0
def test_nearblack_4():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()
    if test_cli_utilities.get_gdalwarp_path() is None:
        pytest.skip()

    gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + ' -wo "INIT_DEST=255" ../gdrivers/data/rgbsmall.tif  tmp/nearblack4_src.tif -srcnodata 0')
    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -q -setalpha -white -nb 0 -of GTiff tmp/nearblack4_src.tif -o tmp/nearblack4.tif')

    ds = gdal.Open('tmp/nearblack4.tif')
    assert ds is not None

    assert ds.GetRasterBand(4).Checksum() == 24151, 'Bad checksum band 0'

    ds = None
def test_nearblack_1():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    (ret, err) = gdaltest.runexternal_out_and_err(
        test_cli_utilities.get_nearblack_path() +
        ' ../gdrivers/data/rgbsmall.tif -nb 0 -of GTiff -o tmp/nearblack1.tif')
    if not (err is None or err == ''):
        gdaltest.post_reason('got error/warning')
        print(err)
        return 'fail'

    src_ds = gdal.Open('../gdrivers/data/rgbsmall.tif')
    ds = gdal.Open('tmp/nearblack1.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 21106:
        print(ds.GetRasterBand(1).Checksum())
        gdaltest.post_reason('Bad checksum band 1')
        return 'fail'

    if ds.GetRasterBand(2).Checksum() != 20736:
        print(ds.GetRasterBand(2).Checksum())
        gdaltest.post_reason('Bad checksum band 2')
        return 'fail'

    if ds.GetRasterBand(3).Checksum() != 21309:
        print(ds.GetRasterBand(3).Checksum())
        gdaltest.post_reason('Bad checksum band 3')
        return 'fail'

    src_gt = src_ds.GetGeoTransform()
    dst_gt = ds.GetGeoTransform()
    for i in range(6):
        if abs(src_gt[i] - dst_gt[i]) > 1e-10:
            gdaltest.post_reason('Bad geotransform')
            return 'fail'

    dst_wkt = ds.GetProjectionRef()
    if dst_wkt.find('AUTHORITY["EPSG","4326"]') == -1:
        gdaltest.post_reason('Bad projection')
        return 'fail'

    src_ds = None
    ds = None

    return 'success'
Exemplo n.º 12
0
def test_nearblack_6():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    shutil.copy('tmp/nearblack5.tif', 'tmp/nearblack6.tif')
    shutil.copy('tmp/nearblack5.tif.msk', 'tmp/nearblack6.tif.msk')

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -setmask -nb 0 -of GTiff tmp/nearblack6.tif')

    ds = gdal.Open('tmp/nearblack6.tif')
    assert ds is not None

    assert ds.GetRasterBand(1).GetMaskBand().Checksum() == 22002, \
        'Bad checksum mask band'

    ds = None
Exemplo n.º 13
0
def test_nearblack_1():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif -nb 0 -of GTiff -o tmp/nearblack1.tif')
    if not (err is None or err == ''):
        gdaltest.post_reason('got error/warning')
        print(err)
        return 'fail'

    src_ds = gdal.Open('../gdrivers/data/rgbsmall.tif')
    ds = gdal.Open('tmp/nearblack1.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 21106:
        print(ds.GetRasterBand(1).Checksum())
        gdaltest.post_reason('Bad checksum band 1')
        return 'fail'

    if ds.GetRasterBand(2).Checksum() != 20736:
        print(ds.GetRasterBand(2).Checksum())
        gdaltest.post_reason('Bad checksum band 2')
        return 'fail'

    if ds.GetRasterBand(3).Checksum() != 21309:
        print(ds.GetRasterBand(3).Checksum())
        gdaltest.post_reason('Bad checksum band 3')
        return 'fail'

    src_gt = src_ds.GetGeoTransform()
    dst_gt = ds.GetGeoTransform()
    for i in range(6):
        if abs(src_gt[i] - dst_gt[i]) > 1e-10:
            gdaltest.post_reason('Bad geotransform')
            return 'fail'

    dst_wkt = ds.GetProjectionRef()
    if dst_wkt.find('AUTHORITY["EPSG","4326"]') == -1:
        gdaltest.post_reason('Bad projection')
        return 'fail'

    src_ds = None
    ds = None

    return 'success'
Exemplo n.º 14
0
def test_nearblack_2():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif -setalpha -nb 0 -of GTiff -o tmp/nearblack2.tif -co TILED=YES')

    ds = gdal.Open('tmp/nearblack2.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(4).Checksum() != 22002:
        print(ds.GetRasterBand(4).Checksum())
        gdaltest.post_reason('Bad checksum band 0')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 15
0
def test_nearblack_5():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif --config GDAL_TIFF_INTERNAL_MASK NO -setmask -nb 0 -of GTiff -o tmp/nearblack5.tif -co TILED=YES')

    ds = gdal.Open('tmp/nearblack5.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).GetMaskBand().Checksum() != 22002:
        print(ds.GetRasterBand(1).GetMaskBand().Checksum())
        gdaltest.post_reason('Bad checksum mask band')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 16
0
def test_nearblack_2():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif -setalpha -nb 0 -of GTiff -o tmp/nearblack2.tif -co TILED=YES')

    ds = gdal.Open('tmp/nearblack2.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(4).Checksum() != 22002:
        print(ds.GetRasterBand(4).Checksum())
        gdaltest.post_reason('Bad checksum band 0')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 17
0
def test_nearblack_5():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' ../gdrivers/data/rgbsmall.tif --config GDAL_TIFF_INTERNAL_MASK NO -setmask -nb 0 -of GTiff -o tmp/nearblack5.tif -co TILED=YES')

    ds = gdal.Open('tmp/nearblack5.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).GetMaskBand().Checksum() != 22002:
        print(ds.GetRasterBand(1).GetMaskBand().Checksum())
        gdaltest.post_reason('Bad checksum mask band')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 18
0
def test_nearblack_8():
    if test_cli_utilities.get_nearblack_path() is None:
        pytest.skip()

    src_ds = gdal.Open('../gdrivers/data/rgbsmall.tif')
    gdal.GetDriverByName('GTiff').CreateCopy('tmp/nearblack8.tif', src_ds)
    src_ds = None

    (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_nearblack_path() + ' tmp/nearblack8.tif -nb 0')
    assert (err is None or err == ''), 'got error/warning'

    ds = gdal.Open('tmp/nearblack8.tif')
    assert ds is not None

    assert ds.GetRasterBand(1).Checksum() == 21106, 'Bad checksum band 1'

    assert ds.GetRasterBand(2).Checksum() == 20736, 'Bad checksum band 2'

    assert ds.GetRasterBand(3).Checksum() == 21309, 'Bad checksum band 3'
Exemplo n.º 19
0
def test_nearblack_3():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    shutil.copy('tmp/nearblack2.tif','tmp/nearblack3.tif')
    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -setalpha -nb 0 -of GTiff tmp/nearblack3.tif')

    ds = gdal.Open('tmp/nearblack3.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(4).Checksum() != 22002:
        print(ds.GetRasterBand(4).Checksum())
        gdaltest.post_reason('Bad checksum band 0')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 20
0
def test_nearblack_3():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    shutil.copy('tmp/nearblack2.tif', 'tmp/nearblack3.tif')
    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -setalpha -nb 0 -of GTiff tmp/nearblack3.tif')

    ds = gdal.Open('tmp/nearblack3.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(4).Checksum() != 22002:
        print(ds.GetRasterBand(4).Checksum())
        gdaltest.post_reason('Bad checksum band 0')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 21
0
def test_nearblack_6():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    shutil.copy('tmp/nearblack5.tif','tmp/nearblack6.tif')
    shutil.copy('tmp/nearblack5.tif.msk','tmp/nearblack6.tif.msk')
    
    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -setmask -nb 0 -of GTiff tmp/nearblack6.tif')

    ds = gdal.Open('tmp/nearblack6.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).GetMaskBand().Checksum() != 22002:
        print(ds.GetRasterBand(1).GetMaskBand().Checksum())
        gdaltest.post_reason('Bad checksum mask band')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 22
0
def test_nearblack_6():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    shutil.copy('tmp/nearblack5.tif', 'tmp/nearblack6.tif')
    shutil.copy('tmp/nearblack5.tif.msk', 'tmp/nearblack6.tif.msk')

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -setmask -nb 0 -of GTiff tmp/nearblack6.tif')

    ds = gdal.Open('tmp/nearblack6.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).GetMaskBand().Checksum() != 22002:
        print(ds.GetRasterBand(1).GetMaskBand().Checksum())
        gdaltest.post_reason('Bad checksum mask band')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 23
0
def test_nearblack_4():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'
    if test_cli_utilities.get_gdalwarp_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + ' -wo "INIT_DEST=255" ../gdrivers/data/rgbsmall.tif  tmp/nearblack4_src.tif -srcnodata 0')
    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' -q -setalpha -white -nb 0 -of GTiff tmp/nearblack4_src.tif -o tmp/nearblack4.tif')

    ds = gdal.Open('tmp/nearblack4.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(4).Checksum() != 24151:
        print(ds.GetRasterBand(4).Checksum())
        gdaltest.post_reason('Bad checksum band 0')
        return 'fail'

    ds = None

    return 'success'
Exemplo n.º 24
0
def test_nearblack_7():
    if test_cli_utilities.get_nearblack_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_nearblack_path() + ' data/whiteblackred.tif -o tmp/nearblack7.tif -color 0,0,0 -color 255,255,255 -of GTiff')

    ds = gdal.Open('tmp/nearblack7.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 418 or \
       ds.GetRasterBand(2).Checksum() != 0 or \
       ds.GetRasterBand(3).Checksum() != 0:
        print(ds.GetRasterBand(1).Checksum())
        print(ds.GetRasterBand(2).Checksum())
        print(ds.GetRasterBand(3).Checksum())
        gdaltest.post_reason('Bad checksum')
        return 'fail'

    ds = None

    return 'success'