| | 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 | |
|---|
| | 1109 | def 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 | |
|---|
| | 1167 | def 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 | |
|---|
| | 1224 | def 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 | |
|---|