Beispiel #1
0
def test_gdal2tiles_py_profile_raster_xyz():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    test_py_scripts.run_py_script_as_external_script(
        script_path,
        'gdal2tiles',
        '-q -p raster --xyz -z 0-1 '+test_py_scripts.get_data_path('gdrivers')+'small_world.tif tmp/out_gdal2tiles_smallworld')

    if sys.platform != 'win32':
        # For some reason, the checksums on the kml file on Windows are the ones of the below png
        _verify_raster_band_checksums(
            'tmp/out_gdal2tiles_smallworld/0/0/0.kml',
            expected_cs = [27644, 31968, 38564, 64301]
        )
    _verify_raster_band_checksums(
        'tmp/out_gdal2tiles_smallworld/0/0/0.png',
        expected_cs = [11468, 10719, 27582, 48827]
    )
    _verify_raster_band_checksums(
        'tmp/out_gdal2tiles_smallworld/1/0/0.png',
        expected_cs = [60550, 62572, 46338, 38489]
    )

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)
Beispiel #2
0
def test_gdal2tiles_py_profile_geodetic_tmscompatible_xyz():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    test_py_scripts.run_py_script_as_external_script(
        script_path, 'gdal2tiles',
        '-q -p geodetic --tmscompatible --xyz -z 0-1 ' +
        test_py_scripts.get_data_path('gdrivers') +
        'small_world.tif tmp/out_gdal2tiles_smallworld')

    if sys.platform != 'win32':
        # For some reason, the checksums on the kml file on Windows are the ones of the below png
        _verify_raster_band_checksums(
            'tmp/out_gdal2tiles_smallworld/0/0/0.kml',
            expected_cs=[12361, 18212, 21827, 5934])
    _verify_raster_band_checksums('tmp/out_gdal2tiles_smallworld/0/0/0.png',
                                  expected_cs=[8560, 8031, 7209, 17849])
    _verify_raster_band_checksums('tmp/out_gdal2tiles_smallworld/1/0/0.png',
                                  expected_cs=[2799, 3468, 8686, 17849])

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)
Beispiel #3
0
def test_gdal2tiles_py_profile_raster():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    test_py_scripts.run_py_script_as_external_script(
        script_path,
        'gdal2tiles',
        '-q -p raster -z 0-1 '+test_py_scripts.get_data_path('gdrivers')+'small_world.tif tmp/out_gdal2tiles_smallworld')

    if sys.platform != 'win32':
        # For some reason, the checksums on the kml file on Windows are the ones of the below png
        _verify_raster_band_checksums(
            'tmp/out_gdal2tiles_smallworld/0/0/0.kml',
            expected_cs = [29839, 34244, 42706, 64319]
        )
    _verify_raster_band_checksums(
        'tmp/out_gdal2tiles_smallworld/0/0/0.png',
        expected_cs = [10125, 10802, 27343, 48852]
    )
    _verify_raster_band_checksums(
        'tmp/out_gdal2tiles_smallworld/1/0/0.png',
        expected_cs = [62125, 59756, 43894, 38539]
    )

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)
Beispiel #4
0
def pam_11():

    # Create a read-only directory
    try:
        os.chmod('tmpdirreadonly', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
        shutil.rmtree('tmpdirreadonly')
    except:
        pass
    os.mkdir('tmpdirreadonly')
    shutil.copy('data/byte.tif', 'tmpdirreadonly/byte.tif')

    # FIXME: how do we create a read-only dir on windows ?
    # The following has no effect
    os.chmod('tmpdirreadonly', stat.S_IRUSR | stat.S_IXUSR)

    # Test that the directory is really read-only
    try:
        f = open('tmpdirreadonly/test', 'w')
        if f is not None:
            f.close()
            return 'skip'
    except:
        pass

    # Compute statistics --> the saving as .aux.xml should fail
    ds = gdal.Open('tmpdirreadonly/byte.tif')
    stats = ds.GetRasterBand(1).ComputeStatistics(False)
    if stats[0] != 74:
        gdaltest.post_reason('did not get expected minimum')
        return 'fail'
    gdal.ErrorReset()
    ds = None
    error_msg = gdal.GetLastErrorMsg()
    if error_msg.find('Unable to save auxiliary information') != 0:
        gdaltest.post_reason('warning was expected at that point')
        return 'fail'

    # Check that we actually have no saved statistics
    ds = gdal.Open('tmpdirreadonly/byte.tif')
    stats = ds.GetRasterBand(1).GetStatistics(False, False)
    if stats[3] != -1:
        gdaltest.post_reason('did not expected to have stats at that point')
        return 'fail'
    ds = None

    # This must be run as an external process so we can override GDAL_PAM_PROXY_DIR
    # at the beginning of the process
    import test_py_scripts
    ret = test_py_scripts.run_py_script_as_external_script('.', 'pamproxydb', '-test1')
    if ret.find('success') == -1:
        gdaltest.post_reason('pamproxydb.py -test1 failed %s' % ret)
        return 'fail'

    # Test loading an existing proxydb
    ret = test_py_scripts.run_py_script_as_external_script('.', 'pamproxydb', '-test2')
    if ret.find('success') == -1:
        gdaltest.post_reason('pamproxydb.py -test2 failed %s' % ret)
        return 'fail'

    return 'success'
Beispiel #5
0
def test_gdal2tiles_py_zoom_option():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    # Because of multiprocessing, run as external process, to avoid issues with
    # Ubuntu 12.04 and socket.setdefaulttimeout()
    # as well as on Windows that doesn't manage to fork
    test_py_scripts.run_py_script_as_external_script(
        script_path, 'gdal2tiles', '-q --force-kml --processes=2 -z 0-1 ' +
        test_py_scripts.get_data_path('gdrivers') +
        'small_world.tif tmp/out_gdal2tiles_smallworld')

    _verify_raster_band_checksums('tmp/out_gdal2tiles_smallworld/1/0/0.png',
                                  expected_cs=[24063, 23632, 14707, 17849])

    assert not os.path.exists(
        'tmp/out_gdal2tiles_smallworld/0/0/0.png.aux.xml')
    assert not os.path.exists(
        'tmp/out_gdal2tiles_smallworld/1/0/0.png.aux.xml')

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/doc.kml')
    assert ds is not None, 'did not get kml'
Beispiel #6
0
def test_gdal2tiles_py_resampling_option():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    resampling_list = [
        'average', 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos',
        'antialias', 'mode', 'max', 'min', 'med', 'q1', 'q3'
    ]
    try:
        from PIL import Image
        import numpy
        import osgeo.gdal_array as gdalarray
        del Image, numpy, gdalarray
    except ImportError:
        # 'antialias' resampling is not available
        resampling_list.remove('antialias')

    out_dir = 'tmp/out_gdal2tiles_smallworld'

    for resample in resampling_list:

        shutil.rmtree(out_dir, ignore_errors=True)

        test_py_scripts.run_py_script_as_external_script(
            script_path, 'gdal2tiles', '-q --resampling={0} {1} {2}'.format(
                resample, '../gdrivers/data/small_world.tif', out_dir))

        # very basic check
        ds = gdal.Open('tmp/out_gdal2tiles_smallworld/0/0/0.png')
        if ds is None:
            pytest.fail('resample option {0!r} failed'.format(resample))
        ds = None
Beispiel #7
0
def test_gdal2tiles_py_zoom_option():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    # Because of multiprocessing, run as external process, to avoid issues with
    # Ubuntu 12.04 and socket.setdefaulttimeout()
    # as well as on Windows that doesn't manage to fork
    test_py_scripts.run_py_script_as_external_script(
        script_path, 'gdal2tiles',
        '-q --force-kml --processes=2 -z 0-1 ../gdrivers/data/small_world.tif tmp/out_gdal2tiles_smallworld'
    )

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/1/0/0.png')

    expected_cs = [8130, 10496, 65274, 63715]
    for i in range(4):
        if ds.GetRasterBand(i + 1).Checksum() != expected_cs[i]:
            for j in range(4):
                print(ds.GetRasterBand(j + 1).Checksum())
            pytest.fail('wrong checksum for band %d' % (i + 1))

    ds = None

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/doc.kml')
    assert ds is not None, 'did not get kml'
Beispiel #8
0
def test_exclude_transparent_tiles():
    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    output_folder = 'tmp/test_exclude_transparent_tiles'
    os.makedirs(output_folder)

    try:
        test_py_scripts.run_py_script_as_external_script(
            script_path, 'gdal2tiles',
            '-x -z 14-16 data/test_gdal2tiles_exclude_transparent.tif %s' %
            output_folder)

        # First row totally transparent - no tiles
        tiles_folder = os.path.join(output_folder, '15', '21898')
        dir_files = os.listdir(tiles_folder)
        assert not dir_files, ('Generated empty tiles for row 21898: %s' %
                               dir_files)

        # Second row - only 2 non-transparent tiles
        tiles_folder = os.path.join(output_folder, '15', '21899')
        dir_files = sorted(os.listdir(tiles_folder))
        assert ['22704.png', '22705.png'] == dir_files, \
            ('Generated empty tiles for row 21899: %s' % dir_files)

        # Third row - only 1 non-transparent tile
        tiles_folder = os.path.join(output_folder, '15', '21900')
        dir_files = os.listdir(tiles_folder)
        assert ['22705.png'] == dir_files, \
            ('Generated empty tiles for row 21900: %s' % dir_files)

    finally:
        shutil.rmtree(output_folder)
Beispiel #9
0
def test_gdal2tiles_py_mapml():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_mapml', ignore_errors=True)

    gdal.Translate('tmp/byte_APS.tif',
                   '../gcore/data/byte.tif',
                   options='-a_srs EPSG:5936 -a_ullr 0 40 40 0')

    test_py_scripts.run_py_script_as_external_script(
        script_path, 'gdal2tiles',
        '-q -p APSTILE -w mapml -z 16-18 --url "https://foo" tmp/byte_APS.tif tmp/out_gdal2tiles_mapml'
    )

    mapml = open('tmp/out_gdal2tiles_mapml/mapml.mapml',
                 'rb').read().decode('utf-8')
    #print(mapml)
    assert '<extent units="APSTILE">' in mapml
    assert '<input name="z" type="zoom" value="18" min="16" max="18" />' in mapml
    assert '<input name="x" type="location" axis="column" units="tilematrix" min="122496" max="122496" />' in mapml
    assert '<input name="y" type="location" axis="row" units="tilematrix" min="139647" max="139647" />' in mapml
    assert '<link tref="https://foo/out_gdal2tiles_mapml/{z}/{x}/{y}.png" rel="tile" />' in mapml

    shutil.rmtree('tmp/out_gdal2tiles_mapml', ignore_errors=True)
    gdal.Unlink('tmp/byte_APS.tif')
Beispiel #10
0
def pam_11():

    # Create a read-only directory
    try:
        os.chmod('tmpdirreadonly', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
        shutil.rmtree('tmpdirreadonly')
    except:
        pass
    os.mkdir('tmpdirreadonly')
    shutil.copy('data/byte.tif', 'tmpdirreadonly/byte.tif')

    # FIXME: how do we create a read-only dir on windows ?
    # The following has no effect
    os.chmod('tmpdirreadonly', stat.S_IRUSR | stat.S_IXUSR)

    # Test that the directory is really read-only
    try:
        f = open('tmpdirreadonly/test', 'w')
        if f is not None:
            f.close()
            return 'skip'
    except:
        pass

    # Compute statistics --> the saving as .aux.xml should fail
    ds = gdal.Open('tmpdirreadonly/byte.tif')
    stats = ds.GetRasterBand(1).ComputeStatistics(False)
    if stats[0] != 74:
        gdaltest.post_reason('did not get expected minimum')
        return 'fail'
    gdal.ErrorReset()
    ds = None
    error_msg = gdal.GetLastErrorMsg()
    if error_msg.find('Unable to save auxiliary information') != 0:
        gdaltest.post_reason('warning was expected at that point')
        return 'fail'

    # Check that we actually have no saved statistics
    ds = gdal.Open('tmpdirreadonly/byte.tif')
    stats = ds.GetRasterBand(1).GetStatistics(False, False)
    if stats[3] != -1:
        gdaltest.post_reason('did not expected to have stats at that point')
        return 'fail'
    ds = None

    # This must be run as an external process so we can override GDAL_PAM_PROXY_DIR
    # at the beginning of the process
    import test_py_scripts
    ret = test_py_scripts.run_py_script_as_external_script('.', 'pamproxydb', '-test1')
    if ret.find('success') == -1:
        gdaltest.post_reason('pamproxydb.py -test1 failed %s' % ret)
        return 'fail'

    # Test loading an existing proxydb
    ret = test_py_scripts.run_py_script_as_external_script('.', 'pamproxydb', '-test2')
    if ret.find('success') == -1:
        gdaltest.post_reason('pamproxydb.py -test2 failed %s' % ret)
        return 'fail'

    return 'success'
Beispiel #11
0
def test_gdal2tiles_py_zoom_option():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        return 'skip'

    # Issue with multiprocessing in the chroot
    if os.environ.get('BUILD_NAME', '') == 'trusty_32bit':
        return 'skip'

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    # Because of multiprocessing, run as external process, to avoid issues with
    # Ubuntu 12.04 and socket.setdefaulttimeout()
    # as well as on Windows that doesn't manage to fork
    test_py_scripts.run_py_script_as_external_script(
        script_path,
        'gdal2tiles',
        '-q --processes=2 -z 0-1 ../gdrivers/data/small_world.tif tmp/out_gdal2tiles_smallworld')

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/1/0/0.png')

    expected_cs = [8130, 10496, 65274, 63715]
    for i in range(4):
        if ds.GetRasterBand(i + 1).Checksum() != expected_cs[i]:
            gdaltest.post_reason('wrong checksum for band %d' % (i + 1))
            for j in range(4):
                print(ds.GetRasterBand(j + 1).Checksum())
            return 'fail'

    ds = None

    return 'success'
Beispiel #12
0
def test_gdal2tiles_py_zoom_option():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        return 'skip'

    # Issue with multiprocessing in the chroot
    if os.environ.get('BUILD_NAME', '') in ('trusty_32bit', 'ubuntu_1804'):
        return 'skip'

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    # Because of multiprocessing, run as external process, to avoid issues with
    # Ubuntu 12.04 and socket.setdefaulttimeout()
    # as well as on Windows that doesn't manage to fork
    test_py_scripts.run_py_script_as_external_script(
        script_path,
        'gdal2tiles',
        '-q --processes=2 -z 0-1 ../gdrivers/data/small_world.tif tmp/out_gdal2tiles_smallworld')

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/1/0/0.png')

    expected_cs = [8130, 10496, 65274, 63715]
    for i in range(4):
        if ds.GetRasterBand(i + 1).Checksum() != expected_cs[i]:
            gdaltest.post_reason('wrong checksum for band %d' % (i + 1))
            for j in range(4):
                print(ds.GetRasterBand(j + 1).Checksum())
            return 'fail'

    ds = None

    return 'success'
Beispiel #13
0
def test_gdal2tiles_py_zoom_option():

    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    shutil.rmtree('tmp/out_gdal2tiles_smallworld', ignore_errors=True)

    # Because of multiprocessing, run as external process, to avoid issues with
    # Ubuntu 12.04 and socket.setdefaulttimeout()
    # as well as on Windows that doesn't manage to fork
    test_py_scripts.run_py_script_as_external_script(
        script_path,
        'gdal2tiles',
        '-q --force-kml --processes=2 -z 0-1 ../gdrivers/data/small_world.tif tmp/out_gdal2tiles_smallworld')

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/1/0/0.png')

    expected_cs = [8130, 10496, 65274, 63715]
    for i in range(4):
        if ds.GetRasterBand(i + 1).Checksum() != expected_cs[i]:
            for j in range(4):
                print(ds.GetRasterBand(j + 1).Checksum())
            pytest.fail('wrong checksum for band %d' % (i + 1))

    ds = None

    ds = gdal.Open('tmp/out_gdal2tiles_smallworld/doc.kml')
    assert ds is not None, 'did not get kml'
Beispiel #14
0
def test_exclude_transparent_tiles():
    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        pytest.skip()

    output_folder = 'tmp/test_exclude_transparent_tiles'
    os.makedirs(output_folder)

    try:
        test_py_scripts.run_py_script_as_external_script(
            script_path,
            'gdal2tiles',
            '-x -z 14-16 data/test_gdal2tiles_exclude_transparent.tif %s' % output_folder)

        # First row totally transparent - no tiles
        tiles_folder = os.path.join(output_folder, '15', '21898')
        dir_files = os.listdir(tiles_folder)
        assert not dir_files, ('Generated empty tiles for row 21898: %s' % dir_files)

        # Second row - only 2 non-transparent tiles
        tiles_folder = os.path.join(output_folder, '15', '21899')
        dir_files = sorted(os.listdir(tiles_folder))
        assert ['22704.png', '22705.png'] == dir_files, \
            ('Generated empty tiles for row 21899: %s' % dir_files)

        # Third row - only 1 non-transparent tile
        tiles_folder = os.path.join(output_folder, '15', '21900')
        dir_files = os.listdir(tiles_folder)
        assert ['22705.png'] == dir_files, \
            ('Generated empty tiles for row 21900: %s' % dir_files)

        return

    finally:
        shutil.rmtree(output_folder)
Beispiel #15
0
def test_exclude_transparent_tiles():
    script_path = test_py_scripts.get_py_script('gdal2tiles')
    if script_path is None:
        return 'skip'

    output_folder = 'tmp/test_exclude_transparent_tiles'
    os.makedirs(output_folder)

    try:
        test_py_scripts.run_py_script_as_external_script(
            script_path, 'gdal2tiles',
            '-x -z 14-16 data/test_gdal2tiles_exclude_transparent.tif %s' %
            output_folder)

        # First row totally transparent - no tiles
        tiles_folder = os.path.join(output_folder, '15', '21898')
        dir_files = os.listdir(tiles_folder)
        if dir_files:
            gdaltest.post_reason('Generated empty tiles for row 21898: %s' %
                                 dir_files)
            return 'fail'

        # Second row - only 2 non-transparent tiles
        tiles_folder = os.path.join(output_folder, '15', '21899')
        dir_files = sorted(os.listdir(tiles_folder))
        if ['22704.png', '22705.png'] != dir_files:
            gdaltest.post_reason('Generated empty tiles for row 21899: %s' %
                                 dir_files)
            return 'fail'

        # Third row - only 1 non-transparent tile
        tiles_folder = os.path.join(output_folder, '15', '21900')
        dir_files = os.listdir(tiles_folder)
        if ['22705.png'] != dir_files:
            gdaltest.post_reason('Generated empty tiles for row 21900: %s' %
                                 dir_files)
            return 'fail'

        return 'success'

    finally:
        shutil.rmtree(output_folder)
def gdal_api_proxy_2():

    if sys.version_info < (2, 6, 0):
        return 'skip'

    import test_py_scripts
    ret = test_py_scripts.run_py_script_as_external_script('.', 'gdal_api_proxy', ' \"%s\" -2' % gdaltest.gdalserver_path, display_live_on_parent_stdout=True)

    if ret.find('Failed:    0') == -1:
        return 'fail'

    return 'success'
def gdal_api_proxy_1():

    import test_py_scripts
    import test_cli_utilities
    gdaltest.gdalserver_path = test_cli_utilities.get_cli_utility_path('gdalserver')
    if gdaltest.gdalserver_path is None:
        gdaltest.gdalserver_path = 'gdalserver'

    ret = test_py_scripts.run_py_script_as_external_script('.', 'gdal_api_proxy', ' \"%s\" -1' % gdaltest.gdalserver_path, display_live_on_parent_stdout=True)

    if ret.find('Failed:    0') == -1:
        return 'fail'

    return 'success'
Beispiel #18
0
def http_test_use_capi_store():

    if gdal.GetDriverByName('HTTP') is None:
        return 'skip'

    if sys.platform != 'win32':
        with gdaltest.error_handler():
            return http_test_use_capi_store_sub()

    import test_py_scripts
    ret = test_py_scripts.run_py_script_as_external_script('.', 'gdalhttp', ' -use_capi_store', display_live_on_parent_stdout=True)

    if ret.find('Failed:    0') == -1:
        return 'fail'

    return 'success'
def gdal_api_proxy_3():

    if sys.version_info < (2, 6, 0):
        return 'skip'

    if sys.platform == 'win32':
        return 'skip'

    if sys.platform == 'darwin':
        print("Fails on MacOSX ('ERROR 1: posix_spawnp() failed'. Not sure why.")
        return 'skip'

    import test_py_scripts
    ret = test_py_scripts.run_py_script_as_external_script('.', 'gdal_api_proxy', ' \"%s\" -3' % gdaltest.gdalserver_path, display_live_on_parent_stdout=True)

    if ret.find('Failed:    0') == -1:
        return 'fail'

    return 'success'