Changeset 19928


Ignore:
Timestamp:
Jun 27, 2010 6:18:07 AM (6 years ago)
Author:
rouault
Message:

GTiff: test GetUnitType?() and SetUnitType?()

Location:
trunk/autotest/gcore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/autotest/gcore/tiff_ovr.py

    r19851 r19928  
    13671367    file_size = os.stat('tmp/ovr38.tif')[stat.ST_SIZE]
    13681368
    1369     # The file size is not the same whether the file is created with native
    1370     # endianness or inversed endianness. A bit strange.
    1371     # 17847 : on little-endian host, native endianness
    1372     # 17879 : on little-endian host, inverted endianness
    1373     # 17732 : on big-endian host, native endianness
    1374     # 17867 : on big-endian host, inverted endianness
    1375     if file_size != 17847 and file_size != 17879 and file_size != 17732 and file_size != 17867:
     1369    if file_size > 21000:
    13761370        print(file_size)
    13771371        gdaltest.post_reason( 'did not get expected file size.' )
  • trunk/autotest/gcore/tiff_write.py

    r19846 r19928  
    27942794    offset = ds.GetRasterBand(1).GetOffset()
    27952795    if scale != 100 or offset != 1000:
    2796         gdaltest.post_reason('did not get expected values in internal case')
     2796        gdaltest.post_reason('did not get expected values in internal case (1)')
    27972797        print(scale)
    2798         print(value)
     2798        print(offset)
     2799        return 'fail'
     2800    ds = None
     2801   
     2802    # Test CreateCopy()
     2803    src_ds = gdal.Open('tmp/tiff_write_80.tif')
     2804    ds = gdaltest.tiff_drv.CreateCopy( 'tmp/tiff_write_80_copy.tif', src_ds )
     2805    src_ds = None
     2806    ds = None
     2807    ds = gdal.Open( 'tmp/tiff_write_80_copy.tif')
     2808    scale = ds.GetRasterBand(1).GetScale()
     2809    offset = ds.GetRasterBand(1).GetOffset()
     2810    if scale != 100 or offset != 1000:
     2811        gdaltest.post_reason('did not get expected values in copy')
     2812        print(scale)
     2813        print(offset)
     2814        return 'fail'
     2815    ds = None
     2816    gdaltest.tiff_drv.Delete( 'tmp/tiff_write_80_copy.tif' )
     2817
     2818    # Second part : test unsetting scale & offsets from internal metadata
     2819    ds = gdal.Open('tmp/tiff_write_80.tif', gdal.GA_Update)
     2820    ds.GetRasterBand(1).SetScale(1)
     2821    ds.GetRasterBand(1).SetOffset(0)
     2822    ds = None
     2823
     2824    ds = gdal.Open('tmp/tiff_write_80.tif')
     2825    scale = ds.GetRasterBand(1).GetScale()
     2826    offset = ds.GetRasterBand(1).GetOffset()
     2827    if scale != 1 or offset != 0:
     2828        gdaltest.post_reason('did not get expected values in internal case (2)')
     2829        print(scale)
     2830        print(offset)
    27992831        return 'fail'
    28002832    ds = None
     
    28032835
    28042836
    2805     # Second part : test storing and retrieving scale & offsets from PAM metadata
     2837    # Third part : test storing and retrieving scale & offsets from PAM metadata
    28062838    ds = gdaltest.tiff_drv.Create( 'tmp/tiff_write_80_bis.tif', 1, 1)
    28072839    if ds.GetRasterBand(1).GetScale() != None or ds.GetRasterBand(1).GetOffset() != None:
     
    28262858    offset = ds.GetRasterBand(1).GetOffset()
    28272859    if scale != -100 or offset != -1000:
    2828         gdaltest.post_reason('did not get expected values in PAM case')
     2860        gdaltest.post_reason('did not get expected values in PAM case (1)')
    28292861        print(scale)
    2830         print(value)
    2831         return 'fail'
    2832     ds = None
    2833 
     2862        print(offset)
     2863        return 'fail'
     2864    ds = None
     2865
     2866
     2867    # Fourth part : test unsetting scale & offsets from PAM metadata
     2868    ds = gdal.Open('tmp/tiff_write_80_bis.tif')
     2869    ds.GetRasterBand(1).SetScale(1)
     2870    ds.GetRasterBand(1).SetOffset(0)
     2871    ds = None
     2872
     2873    try:
     2874        # check that there is no more any PAM file
     2875        os.stat('tmp/tiff_write_80_bis.tif.aux.xml')
     2876        gdaltest.post_reason('PAM file should be deleted')
     2877        return 'fail'
     2878    except:
     2879        pass
     2880
     2881    ds = gdal.Open('tmp/tiff_write_80_bis.tif')
     2882    scale = ds.GetRasterBand(1).GetScale()
     2883    offset = ds.GetRasterBand(1).GetOffset()
     2884    if scale != 1 or offset != 0:
     2885        gdaltest.post_reason('did not get expected values in PAM case (2)')
     2886        print(scale)
     2887        print(offset)
     2888        return 'fail'
     2889    ds = None
     2890   
    28342891    gdaltest.tiff_drv.Delete( 'tmp/tiff_write_80_bis.tif' )
    28352892
     
    29783035        gdaltest.post_reason('did not get expected checksum')
    29793036        return 'fail'
     3037
     3038    return 'success'
     3039
     3040###############################################################################
     3041# Test SetUnitType()
     3042
     3043def tiff_write_85():
     3044
     3045    # First part : test storing and retrieving unittype from internal metadata
     3046    ds = gdaltest.tiff_drv.Create( 'tmp/tiff_write_85.tif', 1, 1)
     3047    ds.GetRasterBand(1).SetUnitType('ft')
     3048    ds = None
     3049   
     3050    try:
     3051        # check that it doesn't go to PAM
     3052        os.stat('tmp/tiff_write_85.tif.aux.xml')
     3053        gdaltest.post_reason('got to PAM, but not expected...')
     3054        return 'fail'
     3055    except:
     3056        pass
     3057
     3058    ds = gdal.Open('tmp/tiff_write_85.tif')
     3059    unittype = ds.GetRasterBand(1).GetUnitType()
     3060    if unittype != 'ft':
     3061        gdaltest.post_reason('did not get expected values in internal case (1)')
     3062        print(unittype)
     3063        return 'fail'
     3064    ds = None
     3065   
     3066    # Test CreateCopy()
     3067    src_ds = gdal.Open('tmp/tiff_write_85.tif')
     3068    ds = gdaltest.tiff_drv.CreateCopy( 'tmp/tiff_write_85_copy.tif', src_ds )
     3069    src_ds = None
     3070    ds = None
     3071    ds = gdal.Open( 'tmp/tiff_write_85_copy.tif')
     3072    unittype = ds.GetRasterBand(1).GetUnitType()
     3073    if unittype != 'ft':
     3074        gdaltest.post_reason('did not get expected values in copy')
     3075        print(unittype)
     3076        return 'fail'
     3077    ds = None
     3078    gdaltest.tiff_drv.Delete( 'tmp/tiff_write_85_copy.tif' )
     3079
     3080    # Second part : test unsetting unittype from internal metadata
     3081    ds = gdal.Open('tmp/tiff_write_85.tif', gdal.GA_Update)
     3082    ds.GetRasterBand(1).SetUnitType(None)
     3083    ds = None
     3084
     3085    ds = gdal.Open('tmp/tiff_write_85.tif')
     3086    unittype = ds.GetRasterBand(1).GetUnitType()
     3087    if unittype != '':
     3088        gdaltest.post_reason('did not get expected values in internal case (2)')
     3089        print(unittype)
     3090        return 'fail'
     3091    ds = None
     3092   
     3093    gdaltest.tiff_drv.Delete( 'tmp/tiff_write_85.tif' )
     3094
     3095
     3096    # Third part : test storing and retrieving unittype from PAM metadata
     3097    ds = gdaltest.tiff_drv.Create( 'tmp/tiff_write_85_bis.tif', 1, 1)
     3098    if len(ds.GetRasterBand(1).GetUnitType()) != 0:
     3099        gdaltest.post_reason('expected None values')
     3100        return 'fail'
     3101    ds = None
     3102
     3103    ds = gdal.Open('tmp/tiff_write_85_bis.tif')
     3104    ds.GetRasterBand(1).SetUnitType('ft')
     3105    ds = None
     3106
     3107    try:
     3108        # check that it *goes* to PAM
     3109        os.stat('tmp/tiff_write_85_bis.tif.aux.xml')
     3110    except:
     3111        gdaltest.post_reason('did not go to PAM as expected')
     3112        return 'fail'
     3113
     3114    ds = gdal.Open('tmp/tiff_write_85_bis.tif')
     3115    unittype = ds.GetRasterBand(1).GetUnitType()
     3116    if unittype != 'ft':
     3117        gdaltest.post_reason('did not get expected values in PAM case (1)')
     3118        print(unittype)
     3119        return 'fail'
     3120    ds = None
     3121
     3122    # Fourth part : test unsetting unittype from PAM metadata
     3123    ds = gdal.Open('tmp/tiff_write_85_bis.tif')
     3124    ds.GetRasterBand(1).SetUnitType(None)
     3125    ds = None
     3126
     3127    try:
     3128        # check that there is no more any PAM file
     3129        os.stat('tmp/tiff_write_85_bis.tif.aux.xml')
     3130        gdaltest.post_reason('PAM file should be deleted')
     3131        return 'fail'
     3132    except:
     3133        pass
     3134
     3135    ds = gdal.Open('tmp/tiff_write_85_bis.tif')
     3136    unittype = ds.GetRasterBand(1).GetUnitType()
     3137    if unittype != '':
     3138        gdaltest.post_reason('did not get expected values in PAM case (2)')
     3139        print(unittype)
     3140        return 'fail'
     3141    ds = None
     3142   
     3143    gdaltest.tiff_drv.Delete( 'tmp/tiff_write_85_bis.tif' )
    29803144
    29813145    return 'success'
     
    30763240    tiff_write_83,
    30773241    tiff_write_84,
     3242    tiff_write_85,
    30783243    tiff_write_cleanup ]
    30793244
Note: See TracChangeset for help on using the changeset viewer.