Changeset 14796

Show
Ignore:
Timestamp:
06/30/08 18:51:45 (5 months ago)
Author:
warmerdam
Message:

improve integration with PAM metadata loading and saving (#2448)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/gtiff/geotiff.cpp

    r14738 r14796  
    139139 
    140140    void        ApplyPamInfo(); 
     141    void        PushMetadataToPam(); 
    141142 
    142143    GDALMultiDomainMetadata oGTiffMDMD; 
     
    30173018            if( strlen(pszXML_MD) > 32000 ) 
    30183019            { 
     3020                if( bSrcIsGeoTIFF ) 
     3021                    ((GTiffDataset *) poSrcDS)->PushMetadataToPam(); 
    30193022                CPLError( CE_Warning, CPLE_AppDefined,  
    30203023                          "Lost metadata writing to GeoTIFF ... too large to fit in tag." ); 
     
    30263029            CPLFree( pszXML_MD ); 
    30273030        } 
     3031        else 
     3032        { 
     3033            if( bSrcIsGeoTIFF ) 
     3034                ((GTiffDataset *) poSrcDS)->PushMetadataToPam(); 
     3035        } 
    30283036 
    30293037        CPLDestroyXMLNode( psRoot ); 
     3038    } 
     3039} 
     3040 
     3041/************************************************************************/ 
     3042/*                         PushMetadataToPam()                          */ 
     3043/*                                                                      */ 
     3044/*      When producing a strict profile TIFF or if our aggregate        */ 
     3045/*      metadata is too big for a single tiff tag we may end up         */ 
     3046/*      needing to write it via the PAM mechanisms.  This method        */ 
     3047/*      copies all the appropriate metadata into the PAM level          */ 
     3048/*      metadata object but with special care to avoid copying          */ 
     3049/*      metadata handled in other ways in TIFF format.                  */ 
     3050/************************************************************************/ 
     3051 
     3052void GTiffDataset::PushMetadataToPam() 
     3053 
     3054{ 
     3055    int nBand; 
     3056    for( nBand = 0; nBand <= GetRasterCount(); nBand++ ) 
     3057    { 
     3058        GDALMultiDomainMetadata *poSrcMDMD; 
     3059        GTiffRasterBand *poBand = NULL; 
     3060 
     3061        if( nBand == 0 ) 
     3062            poSrcMDMD = &(this->oGTiffMDMD); 
     3063        else 
     3064        { 
     3065            poBand = (GTiffRasterBand *) GetRasterBand(nBand); 
     3066            poSrcMDMD = &(poBand->oGTiffMDMD); 
     3067        } 
     3068 
     3069/* -------------------------------------------------------------------- */ 
     3070/*      Loop over the available domains.                                */ 
     3071/* -------------------------------------------------------------------- */ 
     3072        int iDomain, i; 
     3073        char **papszDomainList; 
     3074 
     3075        papszDomainList = poSrcMDMD->GetDomainList(); 
     3076        for( iDomain = 0;  
     3077             papszDomainList && papszDomainList[iDomain];  
     3078             iDomain++ ) 
     3079        { 
     3080            char **papszMD = poSrcMDMD->GetMetadata( papszDomainList[iDomain] ); 
     3081 
     3082            if( EQUAL(papszDomainList[iDomain],"RPC") 
     3083                || EQUAL(papszDomainList[iDomain],"IMD")  
     3084                || EQUAL(papszDomainList[iDomain],"_temporary_") ) 
     3085                continue; 
     3086 
     3087            papszMD = CSLDuplicate(papszMD); 
     3088 
     3089            for( i = CSLCount(papszMD)-1; i > 0; i-- ) 
     3090            { 
     3091                if( EQUALN(papszMD[i],"TIFFTAG_",8) 
     3092                    || EQUALN(papszMD[i],GDALMD_AREA_OR_POINT, 
     3093                              strlen(GDALMD_AREA_OR_POINT)) ) 
     3094                    papszMD = CSLRemoveStrings( papszMD, i, 1, NULL ); 
     3095            } 
     3096 
     3097            if( nBand == 0 ) 
     3098                ((GDALPamDataset *) this)-> 
     3099                    SetMetadata( papszMD, papszDomainList[iDomain]); 
     3100            else 
     3101                ((GDALPamRasterBand *) poBand)-> 
     3102                    SetMetadata( papszMD, papszDomainList[iDomain]); 
     3103 
     3104            CSLDestroy( papszMD ); 
     3105        } 
     3106             
     3107/* -------------------------------------------------------------------- */ 
     3108/*      Handle some "special domain" stuff.                             */ 
     3109/* -------------------------------------------------------------------- */ 
     3110        if( poBand != NULL ) 
     3111        { 
     3112            int bSuccess; 
     3113            double dfOffset = poBand->GetOffset( &bSuccess ); 
     3114            double dfScale = poBand->GetScale(); 
     3115 
     3116            if( bSuccess && (dfOffset != 0.0 || dfScale != 1.0) ) 
     3117            { 
     3118                ((GDALPamRasterBand *) poBand)->SetScale( dfScale ); 
     3119                ((GDALPamRasterBand *) poBand)->SetOffset( dfOffset ); 
     3120            } 
     3121        } 
    30303122    } 
    30313123} 
     
    33903482        CPLFree( pszProjection ); 
    33913483        pszProjection = CPLStrdup( pszPamSRS ); 
     3484    } 
     3485 
     3486/* -------------------------------------------------------------------- */ 
     3487/*      Copy any PAM metadata into our GeoTIFF context, but with the    */ 
     3488/*      GeoTIFF context overriding the PAM info.                        */ 
     3489/* -------------------------------------------------------------------- */ 
     3490    char **papszPamDomains = oMDMD.GetDomainList(); 
     3491    int i; 
     3492 
     3493    for( i = 0; papszPamDomains && papszPamDomains[i] != NULL; i++ ) 
     3494    { 
     3495        const char *pszDomain = papszPamDomains[i]; 
     3496        char **papszGT_MD = oGTiffMDMD.GetMetadata( pszDomain ); 
     3497        char **papszPAM_MD = CSLDuplicate(oMDMD.GetMetadata( pszDomain )); 
     3498 
     3499        papszPAM_MD = CSLMerge( papszPAM_MD, papszGT_MD ); 
     3500 
     3501        oGTiffMDMD.SetMetadata( papszPAM_MD, pszDomain ); 
     3502        CSLDestroy( papszPAM_MD ); 
    33923503    } 
    33933504}