Changeset 14679

Show
Ignore:
Timestamp:
06/10/08 00:23:28 (6 months ago)
Author:
warmerdam
Message:

save floating point nodata in IEEE floating point binary format

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/gcore/gdalpamrasterband.cpp

    r13741 r14679  
    8686 
    8787    if( psPam->bNoDataValueSet ) 
     88    { 
    8889        CPLSetXMLValue( psTree, "NoDataValue",  
    8990                        oFmt.Printf( "%.14E", psPam->dfNoDataValue ) ); 
     91 
     92        /* hex encode real floating point values */ 
     93        if( psPam->dfNoDataValue != floor(psPam->dfNoDataValue)  
     94            || psPam->dfNoDataValue != atof(oFmt) ) 
     95        { 
     96            double dfNoDataLittleEndian; 
     97 
     98            dfNoDataLittleEndian = psPam->dfNoDataValue; 
     99            CPL_LSBPTR64( &dfNoDataLittleEndian ); 
     100 
     101            char *pszHexEncoding =  
     102                CPLBinaryToHex( 8, (GByte *) &dfNoDataLittleEndian ); 
     103            CPLSetXMLValue( psTree, "NoDataValue.#le_hex_equiv",pszHexEncoding); 
     104            CPLFree( pszHexEncoding ); 
     105        } 
     106    } 
    90107 
    91108    if( psPam->pszUnitType != NULL ) 
     
    290307    if( CPLGetXMLValue( psTree, "NoDataValue", NULL ) != NULL ) 
    291308    { 
    292         GDALPamRasterBand::SetNoDataValue(  
    293             atof(CPLGetXMLValue( psTree, "NoDataValue", "0" )) ); 
     309        const char *pszLEHex =  
     310            CPLGetXMLValue( psTree, "NoDataValue.le_hex_equiv", NULL ); 
     311        if( pszLEHex != NULL ) 
     312        { 
     313            int nBytes; 
     314            GByte *pabyBin = CPLHexToBinary( pszLEHex, &nBytes ); 
     315            if( nBytes == 8 ) 
     316            { 
     317                CPL_LSBPTR64( pabyBin ); 
     318                 
     319                GDALPamRasterBand::SetNoDataValue( *((double *) pabyBin) ); 
     320            } 
     321            else 
     322            { 
     323                GDALPamRasterBand::SetNoDataValue(  
     324                    atof(CPLGetXMLValue( psTree, "NoDataValue", "0" )) ); 
     325            } 
     326            CPLFree( pabyBin ); 
     327        } 
     328        else 
     329        { 
     330            GDALPamRasterBand::SetNoDataValue(  
     331                atof(CPLGetXMLValue( psTree, "NoDataValue", "0" )) ); 
     332        } 
    294333    } 
    295334