Esempio n. 1
0
def virtualmem_3():
    
    if gdal.GetConfigOption('SKIP_VIRTUALMEM'):
        return 'skip'
    try:
        from osgeo import gdalnumeric
    except:
        return 'skip'

    if not sys.platform.startswith('linux'):
        return 'skip'

    for tmpfile in [ 'tmp/virtualmem_3.img', '/vsimem/virtualmem_3.img' ]:
        ds = gdal.GetDriverByName('EHdr').Create(tmpfile, 400, 300, 2)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Write)
        for y in range(ds.RasterYSize):
            ar1[y].fill(127)
            ar2[y].fill(255)
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        ds = gdal.Open(tmpfile)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Read)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Read)
        ar_127 = gdalnumeric.empty(ds.RasterXSize)
        ar_127.fill(127)
        ar_255 = gdalnumeric.empty(ds.RasterXSize)
        ar_255.fill(255)
        for y in range(ds.RasterYSize):
            if not gdalnumeric.array_equal(ar1[y], ar_127):
                gdaltest.post_reason('fail')
                return 'fail'
            if not gdalnumeric.array_equal(ar2[y], ar_255):
                gdaltest.post_reason('fail')
                return 'fail'
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        gdal.GetDriverByName('EHdr').Delete(tmpfile)

    return 'success'
Esempio n. 2
0
def virtualmem_3():

    if gdal.GetConfigOption('SKIP_VIRTUALMEM'):
        return 'skip'
    try:
        from osgeo import gdalnumeric
    except ImportError:
        return 'skip'

    if not sys.platform.startswith('linux'):
        return 'skip'

    for tmpfile in ['tmp/virtualmem_3.img', '/vsimem/virtualmem_3.img']:
        ds = gdal.GetDriverByName('EHdr').Create(tmpfile, 400, 300, 2)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Write)
        for y in range(ds.RasterYSize):
            ar1[y].fill(127)
            ar2[y].fill(255)
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        ds = gdal.Open(tmpfile)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Read)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Read)
        ar_127 = gdalnumeric.empty(ds.RasterXSize)
        ar_127.fill(127)
        ar_255 = gdalnumeric.empty(ds.RasterXSize)
        ar_255.fill(255)
        for y in range(ds.RasterYSize):
            if not gdalnumeric.array_equal(ar1[y], ar_127):
                gdaltest.post_reason('fail')
                return 'fail'
            if not gdalnumeric.array_equal(ar2[y], ar_255):
                gdaltest.post_reason('fail')
                return 'fail'
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        gdal.GetDriverByName('EHdr').Delete(tmpfile)

    return 'success'
Esempio n. 3
0
def virtualmem_4():

    try:
        from osgeo import gdalnumeric
    except:
        return 'skip'

    if not sys.platform.startswith('linux'):
        return 'skip'

    tmpfile = 'tmp/virtualmem_4.tif'
    for option in [ 'INTERLEAVE=PIXEL', 'INTERLEAVE=BAND' ]:
        try:
            os.unlink(tmpfile)
        except:
            pass
        ds = gdal.GetDriverByName('GTiff').Create(tmpfile, 400, 301, 2, options = [option])
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        if gdal.GetLastErrorMsg().find('mmap() failed') >= 0:
            ar1 = None
            ds = None
            return 'skip'
        ar1 = None
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar1_bis = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Write)
        for y in range(ds.RasterYSize):
            ar1[y].fill(127)
            ar2[y].fill(255)

        val = ar1_bis[0][0]
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar1_bis = None
        ar2 = None
        ds = None
        if val != 127:
            gdaltest.post_reason('fail')
            print(val)
            return 'fail'

        ds = gdal.Open(tmpfile)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Read)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Read)
        ar_127 = gdalnumeric.empty(ds.RasterXSize)
        ar_127.fill(127)
        ar_255 = gdalnumeric.empty(ds.RasterXSize)
        ar_255.fill(255)
        for y in range(ds.RasterYSize):
            if not gdalnumeric.array_equal(ar1[y], ar_127):
                gdaltest.post_reason('fail')
                ar1 = None
                ar2 = None
                ds = None
                return 'fail'
            if not gdalnumeric.array_equal(ar2[y], ar_255):
                gdaltest.post_reason('fail')
                ar1 = None
                ar2 = None
                ds = None
                return 'fail'
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        gdal.GetDriverByName('GTiff').Delete(tmpfile)

    return 'success'
Esempio n. 4
0
def virtualmem_4():

    if gdal.GetConfigOption('SKIP_VIRTUALMEM'):
        return 'skip'
    try:
        from osgeo import gdalnumeric
    except ImportError:
        return 'skip'

    if not sys.platform.startswith('linux'):
        return 'skip'

    tmpfile = 'tmp/virtualmem_4.tif'
    for option in ['INTERLEAVE=PIXEL', 'INTERLEAVE=BAND']:
        try:
            os.unlink(tmpfile)
        except OSError:
            pass
        ds = gdal.GetDriverByName('GTiff').Create(tmpfile, 400, 301, 2, options=[option])
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        if gdal.GetLastErrorMsg().find('mmap() failed') >= 0:
            ar1 = None
            ds = None
            return 'skip'
        ar1 = None
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar1_bis = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Write)
        for y in range(ds.RasterYSize):
            ar1[y].fill(127)
            ar2[y].fill(255)

        val = ar1_bis[0][0]
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar1_bis = None
        ar2 = None
        ds = None
        if val != 127:
            gdaltest.post_reason('fail')
            print(val)
            return 'fail'

        ds = gdal.Open(tmpfile)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Read)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Read)
        ar_127 = gdalnumeric.empty(ds.RasterXSize)
        ar_127.fill(127)
        ar_255 = gdalnumeric.empty(ds.RasterXSize)
        ar_255.fill(255)
        for y in range(ds.RasterYSize):
            if not gdalnumeric.array_equal(ar1[y], ar_127):
                gdaltest.post_reason('fail')
                ar1 = None
                ar2 = None
                ds = None
                return 'fail'
            if not gdalnumeric.array_equal(ar2[y], ar_255):
                gdaltest.post_reason('fail')
                ar1 = None
                ar2 = None
                ds = None
                return 'fail'
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        gdal.GetDriverByName('GTiff').Delete(tmpfile)

    return 'success'
Esempio n. 5
0
def test_virtualmem_4():

    if gdal.GetConfigOption('SKIP_VIRTUALMEM'):
        pytest.skip()
    try:
        from osgeo import gdalnumeric
    except ImportError:
        pytest.skip()

    if not sys.platform.startswith('linux'):
        pytest.skip()

    tmpfile = 'tmp/virtualmem_4.tif'
    for option in ['INTERLEAVE=PIXEL', 'INTERLEAVE=BAND']:
        gdal.Unlink(tmpfile)
        ds = gdal.GetDriverByName('GTiff').Create(tmpfile, 400, 301, 2, options=[option])
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        if gdal.GetLastErrorMsg().find('mmap() failed') >= 0:
            ar1 = None
            ds = None
            pytest.skip()
        ar1 = None
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar1_bis = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Write)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Write)
        for y in range(ds.RasterYSize):
            ar1[y].fill(127)
            ar2[y].fill(255)

        val = ar1_bis[0][0]
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar1_bis = None
        ar2 = None
        ds = None
        assert val == 127

        ds = gdal.Open(tmpfile)
        ar1 = ds.GetRasterBand(1).GetVirtualMemAutoArray(gdal.GF_Read)
        ar2 = ds.GetRasterBand(2).GetVirtualMemAutoArray(gdal.GF_Read)
        ar_127 = gdalnumeric.empty(ds.RasterXSize)
        ar_127.fill(127)
        ar_255 = gdalnumeric.empty(ds.RasterXSize)
        ar_255.fill(255)
        for y in range(ds.RasterYSize):
            if not gdalnumeric.array_equal(ar1[y], ar_127):
                ar1 = None
                ar2 = None
                ds = None
                pytest.fail()
            if not gdalnumeric.array_equal(ar2[y], ar_255):
                ar1 = None
                ar2 = None
                ds = None
                pytest.fail()
        # We need to destroy the array before dataset destruction
        ar1 = None
        ar2 = None
        ds = None

        gdal.GetDriverByName('GTiff').Delete(tmpfile)