Changeset 13407

Show
Ignore:
Timestamp:
12/20/07 19:43:14 (5 months ago)
Author:
mloskot
Message:

branches/1.5 backport: Use NODATA value when determining data type of AAIGrid grid (Ticket #2107)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/autotest/gdrivers/aaigrid.py

    r11065 r13407  
    133133 
    134134############################################################################### 
     135# Verify data type determination from type of nodata  
     136 
     137def aaigrid_6(): 
     138 
     139    ds = gdal.Open( 'data/nodata_float.asc' ) 
     140 
     141    b = ds.GetRasterBand(1) 
     142    if b.GetNoDataValue() != -99999.123: 
     143        gdaltest.post_reason( 'Grid NODATA value wrong or missing.' ) 
     144        return 'fail' 
     145 
     146    if b.DataType != gdal.GDT_Float32: 
     147        gdaltest.post_reason( 'Data type is not Float32!' ) 
     148        return 'fail' 
     149 
     150    return 'success' 
     151 
     152############################################################################### 
    135153 
    136154gdaltest_list = [ 
     
    139157    aaigrid_3, 
    140158    aaigrid_4, 
    141     aaigrid_5 ] 
     159    aaigrid_5, 
     160    aaigrid_6 ] 
    142161   
    143162 
  • branches/1.5/gdal/frmts/aaigrid/aaigriddataset.cpp

    r12835 r13407  
    376376 
    377377{ 
    378     int         i, j; 
    379     GDALDataType eDataType; 
    380     char        **papszTokens; 
     378    int i = 0; 
     379    int j = 0; 
     380    char **papszTokens = NULL; 
     381    GDALDataType eDataType = GDT_Int16; 
     382    GDALDataType eNoDataType = GDT_Int16; 
    381383 
    382384/* -------------------------------------------------------------------- */ 
     
    409411/*      Parse the header.                                               */ 
    410412/* -------------------------------------------------------------------- */ 
    411     double dfCellDX, dfCellDY; 
     413    double dfCellDX = 0; 
     414    double dfCellDY = 0; 
    412415 
    413416    if ( (i = CSLFindString( papszTokens, "ncols" )) < 0 ) 
     
    476479    if( (i = CSLFindString( papszTokens, "NODATA_value" )) >= 0 ) 
    477480    { 
     481        const char* pszNoData = papszTokens[i + 1]; 
     482 
    478483        poDS->bNoDataSet = TRUE; 
    479         poDS->dfNoDataValue = atof(papszTokens[i + 1]); 
     484        poDS->dfNoDataValue = atof(pszNoData); 
     485         
     486        if( strchr(pszNoData, '.' ) != NULL ) 
     487            eNoDataType = GDT_Float32; 
    480488    } 
    481489     
     
    525533/*      Recognize the type of data.                                                                             */ 
    526534/* -------------------------------------------------------------------- */ 
    527  
    528535    CPLAssert( NULL != poDS->fp ); 
    529536 
    530     /* Default value type. */ 
    531     eDataType = GDT_Int16;  
    532  
    533     /* Allocate 100K chunk + 1 extra byte for NULL character. */ 
    534     const size_t nChunkSize = 1024 * 100; 
    535     GByte* pabyChunk = (GByte *) CPLCalloc( nChunkSize + 1, sizeof(GByte) ); 
    536     pabyChunk[nChunkSize] = '\0'; 
    537  
    538     VSIFSeekL( poDS->fp, nStartOfData, SEEK_SET ); 
    539          
    540     /* Scan for dot in subsequent chunks of data. */ 
    541     while( !VSIFEofL( poDS->fp) ) 
    542     { 
    543         VSIFReadL( pabyChunk, sizeof(GByte), nChunkSize, poDS->fp ); 
    544         CPLAssert( pabyChunk[nChunkSize] == '\0' ); 
    545          
    546         if( strchr( (const char *)pabyChunk, '.' ) != NULL ) 
    547         { 
    548             eDataType = GDT_Float32; 
    549             break; 
    550         } 
    551     } 
    552      
    553     /* Deallocate chunk. */ 
    554     VSIFree( pabyChunk ); 
     537    /* Use type of nodata value. */ 
     538    if( poDS->bNoDataSet && eNoDataType == GDT_Float32 ) 
     539    { 
     540        eDataType = GDT_Float32;  
     541    } 
     542    else 
     543    { 
     544        /* Default value type. */ 
     545        eDataType = GDT_Int16; 
     546 
     547        /* Allocate 100K chunk + 1 extra byte for NULL character. */ 
     548        const size_t nChunkSize = 1024 * 100; 
     549        GByte* pabyChunk = (GByte *) CPLCalloc( nChunkSize + 1, sizeof(GByte) ); 
     550        pabyChunk[nChunkSize] = '\0'; 
     551 
     552        VSIFSeekL( poDS->fp, nStartOfData, SEEK_SET ); 
     553 
     554        /* Scan for dot in subsequent chunks of data. */ 
     555        while( !VSIFEofL( poDS->fp) ) 
     556        { 
     557            VSIFReadL( pabyChunk, sizeof(GByte), nChunkSize, poDS->fp ); 
     558            CPLAssert( pabyChunk[nChunkSize] == '\0' ); 
     559 
     560            if( strchr( (const char *)pabyChunk, '.' ) != NULL ) 
     561            { 
     562                eDataType = GDT_Float32; 
     563                break; 
     564            } 
     565        } 
     566 
     567        /* Deallocate chunk. */ 
     568        VSIFree( pabyChunk ); 
     569    } 
    555570 
    556571/* -------------------------------------------------------------------- */