Changeset 14800
- Timestamp:
- 07/02/08 16:19:49 (5 months ago)
- Files:
-
- trunk/gdal/frmts/gtiff/geotiff.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gdal/frmts/gtiff/geotiff.cpp
r14796 r14800 202 202 203 203 // only needed by createcopy and close code. 204 static voidWriteMetadata( GDALDataset *, TIFF *, int, const char *,205 const char *, char ** );204 static int WriteMetadata( GDALDataset *, TIFF *, int, const char *, 205 const char *, char **, int bExcludeRPBandIMGFileWriting = FALSE ); 206 206 static void WriteNoDataValue( TIFF *, double ); 207 207 … … 2907 2907 /************************************************************************/ 2908 2908 2909 voidGTiffDataset::WriteMetadata( GDALDataset *poSrcDS, TIFF *hTIFF,2909 int GTiffDataset::WriteMetadata( GDALDataset *poSrcDS, TIFF *hTIFF, 2910 2910 int bSrcIsGeoTIFF, 2911 2911 const char *pszProfile, 2912 2912 const char *pszTIFFFilename, 2913 char **papszCreationOptions ) 2913 char **papszCreationOptions, 2914 int bExcludeRPBandIMGFileWriting) 2914 2915 2915 2916 { … … 2942 2943 /* -------------------------------------------------------------------- */ 2943 2944 char **papszRPCMD = poSrcDS->GetMetadata("RPC"); 2944 if( papszRPCMD != NULL )2945 if( papszRPCMD != NULL && !bExcludeRPBandIMGFileWriting ) 2945 2946 { 2946 2947 if( EQUAL(pszProfile,"GDALGeoTIFF") ) … … 2958 2959 /* -------------------------------------------------------------------- */ 2959 2960 char **papszIMDMD = poSrcDS->GetMetadata("IMD"); 2960 if( papszIMDMD != NULL )2961 if( papszIMDMD != NULL && !bExcludeRPBandIMGFileWriting) 2961 2962 { 2962 2963 GDALWriteIMDFile( pszTIFFFilename, papszIMDMD ); … … 3013 3014 if( psRoot != NULL ) 3014 3015 { 3016 int bRet = TRUE; 3017 3015 3018 if( EQUAL(pszProfile,"GDALGeoTIFF") ) 3016 3019 { … … 3020 3023 if( bSrcIsGeoTIFF ) 3021 3024 ((GTiffDataset *) poSrcDS)->PushMetadataToPam(); 3025 else 3026 bRet = FALSE; 3022 3027 CPLError( CE_Warning, CPLE_AppDefined, 3023 3028 "Lost metadata writing to GeoTIFF ... too large to fit in tag." ); … … 3033 3038 if( bSrcIsGeoTIFF ) 3034 3039 ((GTiffDataset *) poSrcDS)->PushMetadataToPam(); 3040 else 3041 bRet = FALSE; 3035 3042 } 3036 3043 3037 3044 CPLDestroyXMLNode( psRoot ); 3038 } 3045 3046 return bRet; 3047 } 3048 3049 return TRUE; 3039 3050 } 3040 3051 … … 3087 3098 papszMD = CSLDuplicate(papszMD); 3088 3099 3089 for( i = CSLCount(papszMD)-1; i > 0; i-- )3100 for( i = CSLCount(papszMD)-1; i >= 0; i-- ) 3090 3101 { 3091 3102 if( EQUALN(papszMD[i],"TIFFTAG_",8) … … 3096 3107 3097 3108 if( nBand == 0 ) 3098 ((GDALPamDataset *) this)-> 3099 SetMetadata( papszMD, papszDomainList[iDomain]); 3109 GDALPamDataset::SetMetadata( papszMD, papszDomainList[iDomain]); 3100 3110 else 3101 ((GDALPamRasterBand *) poBand)-> 3102 SetMetadata( papszMD, papszDomainList[iDomain]); 3111 poBand->GDALPamRasterBand::SetMetadata( papszMD, papszDomainList[iDomain]); 3103 3112 3104 3113 CSLDestroy( papszMD ); … … 3116 3125 if( bSuccess && (dfOffset != 0.0 || dfScale != 1.0) ) 3117 3126 { 3118 ((GDALPamRasterBand *) poBand)->SetScale( dfScale );3119 ((GDALPamRasterBand *) poBand)->SetOffset( dfOffset );3127 poBand->GDALPamRasterBand::SetScale( dfScale ); 3128 poBand->GDALPamRasterBand::SetOffset( dfOffset ); 3120 3129 } 3121 3130 } … … 3489 3498 /* -------------------------------------------------------------------- */ 3490 3499 char **papszPamDomains = oMDMD.GetDomainList(); 3491 int i; 3492 3493 for( i = 0; papszPamDomains && papszPamDomains[i] != NULL; i++ ) 3494 { 3495 const char *pszDomain = papszPamDomains[i]; 3500 3501 for( int iDomain = 0; papszPamDomains && papszPamDomains[iDomain] != NULL; iDomain++ ) 3502 { 3503 const char *pszDomain = papszPamDomains[iDomain]; 3496 3504 char **papszGT_MD = oGTiffMDMD.GetMetadata( pszDomain ); 3497 3505 char **papszPAM_MD = CSLDuplicate(oMDMD.GetMetadata( pszDomain )); … … 3501 3509 oGTiffMDMD.SetMetadata( papszPAM_MD, pszDomain ); 3502 3510 CSLDestroy( papszPAM_MD ); 3511 } 3512 3513 for( int i = 1; i <= GetRasterCount(); i++) 3514 { 3515 GTiffRasterBand* poBand = (GTiffRasterBand *)GetRasterBand(i); 3516 papszPamDomains = poBand->oMDMD.GetDomainList(); 3517 3518 for( int iDomain = 0; papszPamDomains && papszPamDomains[iDomain] != NULL; iDomain++ ) 3519 { 3520 const char *pszDomain = papszPamDomains[iDomain]; 3521 char **papszGT_MD = poBand->oGTiffMDMD.GetMetadata( pszDomain ); 3522 char **papszPAM_MD = CSLDuplicate(poBand->oMDMD.GetMetadata( pszDomain )); 3523 3524 papszPAM_MD = CSLMerge( papszPAM_MD, papszGT_MD ); 3525 3526 poBand->oGTiffMDMD.SetMetadata( papszPAM_MD, pszDomain ); 3527 CSLDestroy( papszPAM_MD ); 3528 } 3503 3529 } 3504 3530 } … … 5131 5157 5132 5158 /* -------------------------------------------------------------------- */ 5133 /* Transfer some TIFF specific metadata, if available. Should */ 5134 /* we push this into .pam if we are avoiding GDAL tags? */ 5135 /* -------------------------------------------------------------------- */ 5136 GTiffDataset::WriteMetadata( poSrcDS, hTIFF, FALSE, pszProfile, 5159 /* Transfer some TIFF specific metadata, if available. */ 5160 /* The return value will tell us if we need to try again later with*/ 5161 /* PAM because the profile doesn't allow to write some metadata */ 5162 /* as TIFF tag */ 5163 /* -------------------------------------------------------------------- */ 5164 int bHasWrittenMDInGeotiffTAG = 5165 GTiffDataset::WriteMetadata( poSrcDS, hTIFF, FALSE, pszProfile, 5137 5166 pszFilename, papszOptions ); 5138 5167 … … 5307 5336 5308 5337 poDS->osProfile = pszProfile; 5309 if( EQUAL(pszProfile,"GDALGeoTIFF") ) 5310 { 5311 poDS->CloneInfo( poSrcDS, GCIF_PAM_DEFAULT ); 5338 poDS->CloneInfo( poSrcDS, GCIF_PAM_DEFAULT ); 5339 5340 /* -------------------------------------------------------------------- */ 5341 /* CloneInfo() doesn't merge metadata, it just replaces it totally */ 5342 /* So we have to merge it */ 5343 /* -------------------------------------------------------------------- */ 5344 5345 char **papszSRC_MD = poSrcDS->GetMetadata(); 5346 char **papszDST_MD = CSLDuplicate(poDS->GetMetadata()); 5347 5348 papszDST_MD = CSLMerge( papszDST_MD, papszSRC_MD ); 5349 5350 poDS->SetMetadata( papszDST_MD ); 5351 CSLDestroy( papszDST_MD ); 5352 5353 for( int nBand = 1; nBand <= poDS->GetRasterCount(); nBand++ ) 5354 { 5355 char **papszSRC_MD = poSrcDS->GetRasterBand(nBand)->GetMetadata(); 5356 char **papszDST_MD = CSLDuplicate(poDS->GetRasterBand(nBand)->GetMetadata()); 5357 5358 papszDST_MD = CSLMerge( papszDST_MD, papszSRC_MD ); 5359 5360 poDS->GetRasterBand(nBand)->SetMetadata( papszDST_MD ); 5361 CSLDestroy( papszDST_MD ); 5312 5362 } 5313 5363 5314 5364 hTIFF = (TIFF*) poDS->GetInternalHandle(NULL); 5365 5366 /* -------------------------------------------------------------------- */ 5367 /* Second chance : now that we have a PAM dataset, it is possible */ 5368 /* to write metadata that we couldn't be writen as TIFF tag */ 5369 /* -------------------------------------------------------------------- */ 5370 if (!bHasWrittenMDInGeotiffTAG) 5371 GTiffDataset::WriteMetadata( poDS, hTIFF, TRUE, pszProfile, 5372 pszFilename, papszOptions, TRUE /* don't write RPC and IMG file again */); 5315 5373 5316 5374 /* We must re-set the compression level at this point, since it has */
