Changeset 11543

Show
Ignore:
Timestamp:
05/16/07 13:02:27 (2 years ago)
Author:
warmerdam
Message:

Fix support for reading metadata values larger than 500 characters.
Avoid creating duplicate Metadata tables. (bug #1640)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/frmts/hfa/hfaopen.cpp

    r11327 r11543  
    23212321        if( columnDataPtr == 0 ) 
    23222322            continue; 
    2323  
    2324 /* -------------------------------------------------------------------- */ 
    2325 /*      read up to 500 bytes from the indicated location.               */ 
    2326 /* -------------------------------------------------------------------- */ 
    2327         char szMDValue[501]; 
    2328         int  nMDBytes = sizeof(szMDValue)-1; 
    2329  
    2330         if( VSIFSeekL( hHFA->fp, columnDataPtr, SEEK_SET ) != 0 ) 
    2331             continue; 
    2332  
    2333         nMDBytes = VSIFReadL( szMDValue, 1, nMDBytes, hHFA->fp ); 
    2334         if( nMDBytes == 0 ) 
    2335             continue; 
    2336  
    2337         szMDValue[nMDBytes] = '\0'; 
    2338  
    2339         papszMD = CSLSetNameValue( papszMD, poColumn->GetName(), szMDValue ); 
     2323             
     2324/* -------------------------------------------------------------------- */ 
     2325/*      read up to nMaxNumChars bytes from the indicated location.      */ 
     2326/*      allocate required space temporarily                             */ 
     2327/*      nMaxNumChars should have been set by GDAL orginally so we can   */ 
     2328/*      trust it.                                                       */ 
     2329/* -------------------------------------------------------------------- */ 
     2330        int nMaxNumChars = poColumn->GetIntField( "maxNumChars" ); 
     2331 
     2332        if( nMaxNumChars == 0 ) 
     2333        { 
     2334            papszMD = CSLSetNameValue( papszMD, poColumn->GetName(), "" ); 
     2335        } 
     2336        else 
     2337        { 
     2338            char *pszMDValue = (char*) CPLMalloc(nMaxNumChars); 
     2339 
     2340            if( VSIFSeekL( hHFA->fp, columnDataPtr, SEEK_SET ) != 0 ) 
     2341                continue; 
     2342 
     2343            int nMDBytes = VSIFReadL( pszMDValue, 1, nMaxNumChars, hHFA->fp ); 
     2344            if( nMDBytes == 0 ) 
     2345            { 
     2346                CPLFree( pszMDValue ); 
     2347                continue; 
     2348            } 
     2349 
     2350            pszMDValue[nMaxNumChars-1] = '\0'; 
     2351 
     2352            papszMD = CSLSetNameValue( papszMD, poColumn->GetName(),  
     2353                                       pszMDValue ); 
     2354            CPLFree( pszMDValue ); 
     2355        } 
    23402356    } 
    23412357 
     
    23702386/* -------------------------------------------------------------------- */ 
    23712387/*      Create the Descriptor table.                                    */ 
    2372 /* -------------------------------------------------------------------- */ 
    2373     HFAEntry    *poEdsc_Table; 
    2374  
    2375     poEdsc_Table = new HFAEntry( hHFA, "GDAL_MetaData", "Edsc_Table", 
     2388/*      Check we have no table with this name already                   */ 
     2389/* -------------------------------------------------------------------- */ 
     2390    HFAEntry    *poEdsc_Table = poNode->GetNamedChild( "GDAL_MetaData" ); 
     2391 
     2392    if( poEdsc_Table == NULL || !EQUAL(poEdsc_Table->GetType(),"Edsc_Table") ) 
     2393        poEdsc_Table = new HFAEntry( hHFA, "GDAL_MetaData", "Edsc_Table", 
    23762394                                 poNode ); 
    2377  
     2395         
    23782396    poEdsc_Table->SetIntField( "numrows", 1 ); 
    23792397 
     
    23812399/*      Create the Binning function node.  I am not sure that we        */ 
    23822400/*      really need this though.                                        */ 
    2383 /* -------------------------------------------------------------------- */ 
    2384     HFAEntry       *poEdsc_BinFunction; 
    2385  
    2386     poEdsc_BinFunction = 
    2387         new HFAEntry( hHFA, "#Bin_Function#", "Edsc_BinFunction", 
    2388                       poEdsc_Table ); 
     2401/*      Check it doesn't exist already                                  */ 
     2402/* -------------------------------------------------------------------- */ 
     2403    HFAEntry       *poEdsc_BinFunction =  
     2404        poEdsc_Table->GetNamedChild( "#Bin_Function#" ); 
     2405 
     2406    if( poEdsc_BinFunction == NULL  
     2407        || !EQUAL(poEdsc_BinFunction->GetType(),"Edsc_BinFunction") ) 
     2408        poEdsc_BinFunction = new HFAEntry( hHFA, "#Bin_Function#",  
     2409                                           "Edsc_BinFunction", poEdsc_Table ); 
    23892410 
    23902411    // Because of the BaseData we have to hardcode the size.  
     
    24112432/* -------------------------------------------------------------------- */ 
    24122433/*      Create the Edsc_Column.                                         */ 
    2413 /* -------------------------------------------------------------------- */ 
    2414         poEdsc_Column = new HFAEntry( hHFA, pszKey, "Edsc_Column", 
    2415                                       poEdsc_Table ); 
     2434/*      Check it doesn't exist already                                  */ 
     2435/* -------------------------------------------------------------------- */ 
     2436        poEdsc_Column = poEdsc_Table->GetNamedChild(pszKey); 
     2437 
     2438        if( poEdsc_Column == NULL  
     2439            || !EQUAL(poEdsc_Column->GetType(),"Edsc_Column") ) 
     2440            poEdsc_Column = new HFAEntry( hHFA, pszKey, "Edsc_Column", 
     2441                                          poEdsc_Table ); 
     2442 
    24162443        poEdsc_Column->SetIntField( "numRows", 1 ); 
    24172444        poEdsc_Column->SetStringField( "dataType", "string" );