Changeset 14478

Show
Ignore:
Timestamp:
05/16/08 16:34:08 (2 months ago)
Author:
rouault
Message:

Set AAIGRID raster band data type to Int32 if there are no floating point values in the first 100K chunk and in no data, otherwise choose Float32 (#2369)

Files:

Legend:

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

    r14476 r14478  
    223223                ((float *) pImage)[iPixel] = (float) atof(szToken); 
    224224            else 
    225                 ((GInt16 *) pImage)[iPixel] = (GInt16) atoi(szToken); 
     225                ((GInt32 *) pImage)[iPixel] = (GInt32) atoi(szToken); 
    226226        } 
    227227         
     
    380380    int j = 0; 
    381381    char **papszTokens = NULL; 
    382     GDALDataType eDataType = GDT_Int16; 
     382 
     383    /* Default data type */ 
     384    GDALDataType eDataType = GDT_Int32; 
    383385 
    384386/* -------------------------------------------------------------------- */ 
     
    483485        poDS->bNoDataSet = TRUE; 
    484486        poDS->dfNoDataValue = atof(pszNoData); 
     487        if( strchr( pszNoData, '.' ) != NULL ) 
     488        { 
     489            eDataType = GDT_Float32; 
     490        } 
    485491    } 
    486492     
     
    534540    /* Use bigger data type. */ 
    535541    if( poDS->bNoDataSet 
    536         && ( SHRT_MIN > poDS->dfNoDataValue || poDS->dfNoDataValue > SHRT_MAX) ) 
     542        && ( INT_MIN > poDS->dfNoDataValue || poDS->dfNoDataValue > INT_MAX) ) 
    537543    { 
    538544        eDataType = GDT_Float32;  
     
    540546    else 
    541547    { 
    542         /* Default value type. */ 
    543         eDataType = GDT_Int16; 
    544  
    545548        /* Allocate 100K chunk + 1 extra byte for NULL character. */ 
    546549        const size_t nChunkSize = 1024 * 100; 
     
    944947        poDriver->SetMetadataItem( GDAL_DMD_EXTENSION, "asc" ); 
    945948        poDriver->SetMetadataItem( GDAL_DMD_CREATIONDATATYPES,  
    946                                    "Byte UInt16 Int16 Float32" ); 
     949                                   "Byte UInt16 Int16 Int32 Float32" ); 
    947950 
    948951        poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );