Changeset 14724

Show
Ignore:
Timestamp:
06/18/08 16:20:38 (6 months ago)
Author:
rouault
Message:

Add DECIMAL_PRECISION creation option for AAIGRID (#2430)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/aaigrid/aaigriddataset.cpp

    r14478 r14724  
    768768 
    769769/* -------------------------------------------------------------------- */ 
     770/*     Builds the format string used for printing float values.         */ 
     771/* -------------------------------------------------------------------- */ 
     772    char szFormatFloat[32]; 
     773    strcpy(szFormatFloat, " %6.20g"); 
     774    const char *pszDecimalPrecision =  
     775        CSLFetchNameValue( papszOptions, "DECIMAL_PRECISION" ); 
     776    if (pszDecimalPrecision) 
     777    { 
     778        int nDecimal = atoi(pszDecimalPrecision); 
     779        if (nDecimal >= 0) 
     780            sprintf(szFormatFloat, " %%.%df", nDecimal); 
     781    } 
     782 
     783/* -------------------------------------------------------------------- */ 
    770784/*      Loop over image, copying image data.                            */ 
    771785/* -------------------------------------------------------------------- */ 
     
    814828            for ( iPixel = 0; iPixel < nXSize; iPixel++ ) 
    815829            { 
    816                 sprintf( szHeader, " %6.20g", padfScanline[iPixel] ); 
     830                sprintf( szHeader, szFormatFloat, padfScanline[iPixel] ); 
    817831                if( VSIFWriteL( szHeader, strlen(szHeader), 1, fpImage ) != 1 ) 
    818832                { 
     
    953967"<CreationOptionList>\n" 
    954968"   <Option name='FORCE_CELLSIZE' type='boolean' description='Force use of CELLSIZE, default is FALSE.'/>\n" 
     969"   <Option name='DECIMAL_PRECISION' type='int' description='Number of decimal when writing floating-point numbers.'/>\n" 
    955970"</CreationOptionList>\n" ); 
    956971 
  • trunk/gdal/frmts/frmt_various.html

    r14557 r14724  
    3030use the FORCE_CELLSIZE=YES creation option or resample the input to have  
    3131square pixels.<P> 
     32 
     33When writing floating-point values, the driver uses the "%6.20g" format 
     34pattern as a default. You can consult a <a href="http://en.wikipedia.org/wiki/Printf"> 
     35reference manual</a> for printf to have an idea of the exact behaviour of this ;-). 
     36You can alternatively specify the number of decimal places with the DECIMAL_PRECISION creation 
     37option. For example, DECIMAL_PRECISION=3 will output numbers with 3 decimal places.<p> 
    3238 
    3339The <a href="#AIG">AIG</a> driver is also available