Changeset 14801

Show
Ignore:
Timestamp:
07/02/08 16:20:12 (5 months ago)
Author:
rouault
Message:

Test improved PAM metadata support with GeoTIFF in PROFILE=BASELINE/GeoTIFF mode (#2448)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/gcore/data/byte.vrt

    r14386 r14801  
    1414      <DstRect xOff="0" yOff="0" xSize="20" ySize="20"/> 
    1515    </SimpleSource> 
     16    <Metadata> 
     17      <MDI key="testBand">testvalueBand</MDI> 
     18    </Metadata> 
    1619  </VRTRasterBand> 
    1720</VRTDataset> 
  • trunk/autotest/gcore/tiff_write.py

    r14562 r14801  
    441441 
    442442    md = ds.GetMetadata() 
     443    if not md.has_key('test'): 
     444        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     445        return 'fail' 
     446 
     447    md = ds.GetRasterBand(1).GetMetadata() 
     448    if not md.has_key('testBand'): 
     449        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     450        return 'fail' 
     451 
     452    ds = None 
     453 
     454    try: 
     455        os.remove( 'tmp/tw_15.tif.aux.xml' ) 
     456    except: 
     457        try: 
     458            os.stat( 'tmp/tw_15.tif.aux.xml' ) 
     459        except: 
     460            gdaltest.post_reason( 'No .aux.xml file.' ) 
     461            return 'fail' 
     462            pass 
     463 
     464    ds = gdal.Open( 'tmp/tw_15.tif' ) 
     465 
     466    md = ds.GetMetadata() 
    443467    if md.has_key('test'): 
    444468        gdaltest.post_reason( 'Metadata written to BASELINE file.' ) 
    445469        return 'fail' 
    446470 
     471    md = ds.GetRasterBand(1).GetMetadata() 
     472    if md.has_key('testBand'): 
     473        gdaltest.post_reason( 'Metadata written to BASELINE file.' ) 
     474        return 'fail' 
     475 
    447476    ds = None 
    448477 
     
    465494     
    466495    ds.SetMetadata( {'test':'testvalue'} ) 
     496    ds.GetRasterBand(1).SetMetadata( {'testBand':'testvalueBand'} ) 
    467497 
    468498    ds.SetGeoTransform( (10,5,0,30,0,-5) ) 
     
    480510 
    481511    md = ds.GetMetadata() 
     512    if not md.has_key('test'): 
     513        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     514        return 'fail' 
     515 
     516    md = ds.GetRasterBand(1).GetMetadata() 
     517    if not md.has_key('testBand'): 
     518        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     519        return 'fail' 
     520 
     521    ds = None 
     522 
     523    try: 
     524        os.remove( 'tmp/tw_16.tif.aux.xml' ) 
     525    except: 
     526        try: 
     527            os.stat( 'tmp/tw_16.tif.aux.xml' ) 
     528        except: 
     529            gdaltest.post_reason( 'No .aux.xml file.' ) 
     530            return 'fail' 
     531            pass 
     532 
     533    ds = gdal.Open( 'tmp/tw_16.tif' ) 
     534 
     535    md = ds.GetMetadata() 
    482536    if md.has_key('test'): 
     537        gdaltest.post_reason( 'Metadata written to BASELINE file.' ) 
     538        return 'fail' 
     539 
     540    md = ds.GetRasterBand(1).GetMetadata() 
     541    if md.has_key('testBand'): 
    483542        gdaltest.post_reason( 'Metadata written to BASELINE file.' ) 
    484543        return 'fail' 
     
    10431102 
    10441103    return 'success' 
     1104 
     1105############################################################################### 
     1106# Test that metadata is written in .aux.xml file in GeoTIFF profile with CreateCopy 
     1107# (BASELINE is tested by tiff_write_15) 
     1108 
     1109def tiff_write_33(): 
     1110 
     1111    drv = gdal.GetDriverByName( 'GTiff' ) 
     1112 
     1113    ds_in = gdal.Open('data/byte.vrt') 
     1114 
     1115    ds = drv.CreateCopy( 'tmp/tw_33.tif', ds_in, options=['PROFILE=GeoTIFF'] ) 
     1116 
     1117    ds_in = None 
     1118 
     1119    ds = None 
     1120 
     1121    ds = gdal.Open( 'tmp/tw_33.tif' ) 
     1122 
     1123    md = ds.GetMetadata() 
     1124    if not md.has_key('test'): 
     1125        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     1126        return 'fail' 
     1127 
     1128    md = ds.GetRasterBand(1).GetMetadata() 
     1129    if not md.has_key('testBand'): 
     1130        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     1131        return 'fail' 
     1132 
     1133    ds = None 
     1134 
     1135    try: 
     1136        os.remove( 'tmp/tw_33.tif.aux.xml' ) 
     1137    except: 
     1138        try: 
     1139            os.stat( 'tmp/tw_33.tif.aux.xml' ) 
     1140        except: 
     1141            gdaltest.post_reason( 'No .aux.xml file.' ) 
     1142            return 'fail' 
     1143            pass 
     1144 
     1145    ds = gdal.Open( 'tmp/tw_33.tif' ) 
     1146 
     1147    md = ds.GetMetadata() 
     1148    if md.has_key('test'): 
     1149        gdaltest.post_reason( 'Metadata written to GeoTIFF file.' ) 
     1150        return 'fail' 
     1151 
     1152    md = ds.GetRasterBand(1).GetMetadata() 
     1153    if md.has_key('testBand'): 
     1154        gdaltest.post_reason( 'Metadata written to GeoTIFF file.' ) 
     1155        return 'fail' 
     1156 
     1157    ds = None 
     1158 
     1159    drv.Delete( 'tmp/tw_33.tif' ) 
     1160 
     1161    return 'success' 
     1162 
     1163############################################################################### 
     1164# Test that metadata is written in .aux.xml file in GeoTIFF profile with Create 
     1165# (BASELINE is tested by tiff_write_16) 
     1166 
     1167def tiff_write_34(): 
     1168 
     1169    drv = gdal.GetDriverByName( 'GTiff' ) 
     1170 
     1171    ds = drv.Create( 'tmp/tw_34.tif', 1, 1, gdal.GDT_Byte, 
     1172                     options=['PROFILE=GeoTIFF'] ) 
     1173    ds.SetMetadata( {'test':'testvalue'} ) 
     1174    ds.GetRasterBand(1).SetMetadata( {'testBand':'testvalueBand'} ) 
     1175 
     1176    ds = None 
     1177 
     1178    ds = gdal.Open( 'tmp/tw_34.tif' ) 
     1179 
     1180    md = ds.GetMetadata() 
     1181    if not md.has_key('test'): 
     1182        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     1183        return 'fail' 
     1184 
     1185    md = ds.GetRasterBand(1).GetMetadata() 
     1186    if not md.has_key('testBand'): 
     1187        gdaltest.post_reason( 'Metadata absent from .aux.xml file.' ) 
     1188        return 'fail' 
     1189 
     1190    ds = None 
     1191 
     1192    try: 
     1193        os.remove( 'tmp/tw_34.tif.aux.xml' ) 
     1194    except: 
     1195        try: 
     1196            os.stat( 'tmp/tw_34.tif.aux.xml' ) 
     1197        except: 
     1198            gdaltest.post_reason( 'No .aux.xml file.' ) 
     1199            return 'fail' 
     1200            pass 
     1201 
     1202    ds = gdal.Open( 'tmp/tw_34.tif' ) 
     1203 
     1204    md = ds.GetMetadata() 
     1205    if md.has_key('test'): 
     1206        gdaltest.post_reason( 'Metadata written to GeoTIFF file.' ) 
     1207        return 'fail' 
     1208 
     1209    md = ds.GetRasterBand(1).GetMetadata() 
     1210    if md.has_key('testBand'): 
     1211        gdaltest.post_reason( 'Metadata written to GeoTIFF file.' ) 
     1212        return 'fail' 
     1213 
     1214    ds = None 
     1215 
     1216    drv.Delete( 'tmp/tw_34.tif' ) 
     1217 
     1218    return 'success' 
     1219 
     1220############################################################################### 
     1221# Test fallback from internal storage of Geotiff metadata to PAM storage 
     1222# when metadata is too big to fit into the GDALGeotiff tag 
     1223 
     1224def tiff_write_35(): 
     1225 
     1226    # I've no idea why this works, and why this rolled in a 
     1227    # loop doesn't work... Python gurus please fix that ! 
     1228    big_string = 'a' 
     1229    big_string = big_string + big_string 
     1230    big_string = big_string + big_string 
     1231    big_string = big_string + big_string 
     1232    big_string = big_string + big_string 
     1233    big_string = big_string + big_string 
     1234    big_string = big_string + big_string 
     1235    big_string = big_string + big_string 
     1236    big_string = big_string + big_string 
     1237    big_string = big_string + big_string 
     1238    big_string = big_string + big_string 
     1239    big_string = big_string + big_string 
     1240    big_string = big_string + big_string 
     1241    big_string = big_string + big_string 
     1242    big_string = big_string + big_string 
     1243    big_string = big_string + big_string 
     1244 
     1245    drv = gdal.GetDriverByName( 'GTiff' ) 
     1246 
     1247    ds = drv.Create( 'tmp/tw_35.tif', 1, 1, gdal.GDT_Byte ) 
     1248 
     1249    md = {} 
     1250    md['test'] = big_string 
     1251    ds.SetMetadata( md ) 
     1252 
     1253    md = ds.GetMetadata() 
     1254 
     1255    gdal.PushErrorHandler('CPLQuietErrorHandler') 
     1256    ds = None 
     1257    gdal.PopErrorHandler() 
     1258 
     1259    try: 
     1260        os.stat( 'tmp/tw_35.tif.aux.xml' ) 
     1261    except: 
     1262        gdaltest.post_reason( 'No .aux.xml file.' ) 
     1263        return 'fail' 
     1264        pass 
     1265 
     1266    gdal.PushErrorHandler('CPLQuietErrorHandler') 
     1267    ds = gdal.Open( 'tmp/tw_35.tif' ) 
     1268    gdal.PopErrorHandler() 
     1269 
     1270    md = ds.GetMetadata() 
     1271    if not md.has_key('test') or len(md['test']) != 32768: 
     1272        gdaltest.post_reason( 'Did not get expected metadata.' ) 
     1273        return 'fail' 
     1274 
     1275    ds = None 
     1276 
     1277    drv.Delete( 'tmp/tw_35.tif' ) 
     1278 
     1279    return 'success' 
     1280 
    10451281 
    10461282def tiff_write_cleanup(): 
     
    10821318    tiff_write_31, 
    10831319    tiff_write_32, 
     1320    tiff_write_33, 
     1321    tiff_write_34, 
     1322    tiff_write_35, 
    10841323    tiff_write_cleanup ] 
    10851324