LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/avc - ogravce00datasource.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 64 45 70.3 %
Date: 2012-12-26 Functions: 10 5 50.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogravce00datasource.cpp 24747 2012-08-08 00:13:30Z warmerdam $
       3                 :  *
       4                 :  * Project:  OGR
       5                 :  * Purpose:  Implements OGRAVCE00DataSource class.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *           James Flemer <jflemer@alum.rpi.edu>
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com>
      11                 :  * Copyright (c) 2006, James Flemer <jflemer@alum.rpi.edu>
      12                 :  *
      13                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      14                 :  * copy of this software and associated documentation files (the "Software"),
      15                 :  * to deal in the Software without restriction, including without limitation
      16                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      17                 :  * and/or sell copies of the Software, and to permit persons to whom the
      18                 :  * Software is furnished to do so, subject to the following conditions:
      19                 :  *
      20                 :  * The above copyright notice and this permission notice shall be included
      21                 :  * in all copies or substantial portions of the Software.
      22                 :  *
      23                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      24                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      25                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      26                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      27                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      28                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      29                 :  * DEALINGS IN THE SOFTWARE.
      30                 :  ****************************************************************************/
      31                 : 
      32                 : #include "ogr_avc.h"
      33                 : #include "cpl_conv.h"
      34                 : #include "cpl_string.h"
      35                 : 
      36                 : CPL_CVSID("$Id: ogravce00datasource.cpp 24747 2012-08-08 00:13:30Z warmerdam $");
      37                 : 
      38                 : /************************************************************************/
      39                 : /*                        OGRAVCE00DataSource()                         */
      40                 : /************************************************************************/
      41                 : 
      42             350 : OGRAVCE00DataSource::OGRAVCE00DataSource()
      43             350 :     : nLayers(0), pszName(NULL), psE00(NULL), papoLayers(NULL)
      44                 : {
      45             350 : }
      46                 : 
      47                 : /************************************************************************/
      48                 : /*                        ~OGRAVCE00DataSource()                        */
      49                 : /************************************************************************/
      50                 : 
      51             350 : OGRAVCE00DataSource::~OGRAVCE00DataSource()
      52                 : 
      53                 : {
      54             350 :     if( psE00 )
      55                 :     {
      56               1 :         AVCE00ReadCloseE00( psE00 );
      57               1 :         psE00 = NULL;
      58                 :     }
      59                 : 
      60             350 :     CPLFree( pszName );
      61                 : 
      62             352 :     for( int i = 0; i < nLayers; i++ )
      63               2 :         delete papoLayers[i];
      64                 :     
      65             350 :     CPLFree( papoLayers );
      66             350 : }
      67                 : 
      68                 : /************************************************************************/
      69                 : /*                                Open()                                */
      70                 : /************************************************************************/
      71                 : 
      72             350 : int OGRAVCE00DataSource::Open( const char * pszNewName, int bTestOpen )
      73                 : 
      74                 : {
      75                 : /* -------------------------------------------------------------------- */
      76                 : /*      Open the source file.  Supress error reporting if we are in     */
      77                 : /*      TestOpen mode.                                                  */
      78                 : /* -------------------------------------------------------------------- */
      79             350 :     int bCompressed = FALSE;
      80                 : 
      81             350 :     if( bTestOpen )
      82             350 :         CPLPushErrorHandler( CPLQuietErrorHandler );
      83                 : 
      84             350 :     psE00 = AVCE00ReadOpenE00(pszNewName);
      85                 : 
      86             350 :     if( CPLGetLastErrorNo() == CPLE_OpenFailed
      87                 :         && strstr(CPLGetLastErrorMsg(),"compressed E00") != NULL ) 
      88                 :     {
      89               1 :         bCompressed = TRUE;
      90                 :     }
      91                 : 
      92             350 :     if( bTestOpen )
      93                 :     {
      94             350 :         CPLPopErrorHandler();
      95             350 :         CPLErrorReset();
      96                 :     }
      97                 : 
      98             350 :     if( psE00 == NULL )
      99                 :     {
     100             349 :         if( bCompressed ) 
     101                 :         {
     102                 :             CPLError(CE_Failure, CPLE_OpenFailed, 
     103                 :                      "This looks like a compressed E00 file and cannot be "
     104                 :                      "processed directly. You may need to uncompress it "
     105                 :                      "first using the E00compr library or the e00conv "
     106               1 :                      "program." );
     107                 :         }
     108             349 :         return FALSE;
     109                 :     }
     110                 : 
     111               1 :     pszName = CPLStrdup( pszNewName );
     112                 :     /* pszCoverageName = CPLStrdup( psE00->pszCoverName ); */
     113               1 :     pszCoverageName = CPLStrdup( pszNewName );
     114                 : 
     115                 : /* -------------------------------------------------------------------- */
     116                 : /*      Create layers for the "interesting" sections of the coverage.   */
     117                 : /* -------------------------------------------------------------------- */
     118                 :     int iSection;
     119                 : 
     120                 :     papoLayers = (OGRAVCE00Layer **)
     121               1 :         CPLCalloc( sizeof(OGRAVCE00Layer *), psE00->numSections );
     122               1 :     nLayers = 0;
     123                 : 
     124               8 :     for( iSection = 0; iSection < psE00->numSections; iSection++ )
     125                 :     {
     126               7 :         AVCE00Section *psSec = psE00->pasSections + iSection;
     127                 : 
     128               7 :         switch( psSec->eType )
     129                 :         {
     130                 :           case AVCFileARC:
     131                 :           case AVCFilePAL:
     132                 :           case AVCFileCNT:
     133                 :           case AVCFileLAB:
     134                 :           case AVCFileRPL:
     135                 :           case AVCFileTXT:
     136               2 :             papoLayers[nLayers++] = new OGRAVCE00Layer( this, psSec );
     137               2 :             break;
     138                 : 
     139                 :           case AVCFileTX6:
     140               0 :             break;
     141                 : 
     142                 :           case AVCFileTABLE:
     143               4 :             CheckAddTable(psSec);
     144                 :             break;
     145                 : 
     146                 :           case AVCFilePRJ:
     147                 :           {
     148                 : #if 0
     149                 :               poSRS = new OGRSpatialReference();
     150                 :               char  **papszPRJ;
     151                 :               AVCE00File *hFile;
     152                 :               
     153                 :               hFile = AVCE00ReadOpen(psE00->pszCoverPath, 
     154                 :                                      psSec->pszFilename, 
     155                 :                                      psE00->eCoverType, 
     156                 :                                      psSec->eType,
     157                 :                                      psE00->psDBCSInfo);
     158                 :               if( hFile && poSRS == NULL )
     159                 :               {
     160                 :                   papszPRJ = AVCE00ReadNextPrj( hFile );
     161                 : 
     162                 :                   poSRS = new OGRSpatialReference();
     163                 :                   if( poSRS->importFromESRI( papszPRJ ) != OGRERR_NONE )
     164                 :                   {
     165                 :                       CPLError( CE_Warning, CPLE_AppDefined, 
     166                 :                                 "Failed to parse PRJ section, ignoring." );
     167                 :                       delete poSRS;
     168                 :                       poSRS = NULL;
     169                 :                   }
     170                 :                   AVCE00ReadClose( hFile );
     171                 :               }
     172                 : #endif
     173                 :           }
     174                 :           break;
     175                 : 
     176                 :           default:
     177                 :             ;
     178                 :         }
     179                 :     }
     180                 :     
     181               1 :     return nLayers > 0;
     182                 : }
     183                 : 
     184               4 : int OGRAVCE00DataSource::CheckAddTable( AVCE00Section *psTblSection )
     185                 : {
     186               4 :     int i, nCount = 0;
     187              12 :     for (i = 0; i < nLayers; ++i)
     188                 :     {
     189               8 :         if (papoLayers[i]->CheckSetupTable(psTblSection))
     190               0 :             ++nCount;
     191                 :     }
     192               4 :     return nCount;
     193                 : }
     194                 : 
     195                 : /************************************************************************/
     196                 : /*                           TestCapability()                           */
     197                 : /************************************************************************/
     198                 : 
     199               0 : int OGRAVCE00DataSource::TestCapability( const char * pszCap )
     200                 : 
     201                 : {
     202               0 :     return FALSE;
     203                 : }
     204                 : 
     205                 : /************************************************************************/
     206                 : /*                              GetLayer()                              */
     207                 : /************************************************************************/
     208                 : 
     209               1 : OGRLayer *OGRAVCE00DataSource::GetLayer( int iLayer )
     210                 : 
     211                 : {
     212               1 :     if( iLayer < 0 || iLayer >= nLayers )
     213               0 :         return NULL;
     214                 :     else
     215               1 :         return papoLayers[iLayer];
     216                 : }
     217                 : 
     218                 : /************************************************************************/
     219                 : /*                           GetSpatialRef()                            */
     220                 : /************************************************************************/
     221               0 : OGRSpatialReference *OGRAVCE00DataSource::GetSpatialRef()
     222                 : {
     223               0 :     if (NULL == poSRS && psE00 != NULL)
     224                 :     /* if (psE00 != NULL) */
     225                 :     {
     226                 :         int iSection;
     227                 :         AVCE00Section *psSec;
     228                 :         char **pszPRJ;
     229                 : 
     230               0 :         for( iSection = 0; iSection < psE00->numSections; iSection++ )
     231                 :         {
     232               0 :             psSec = psE00->pasSections + iSection;
     233               0 :             if (psSec->eType == AVCFilePRJ)
     234                 :             {
     235               0 :             AVCE00ReadGotoSectionE00(psE00, psSec, 0);
     236               0 :               pszPRJ = (char **)AVCE00ReadNextObjectE00(psE00);
     237               0 :                 poSRS = new OGRSpatialReference();
     238               0 :                 if( poSRS->importFromESRI( pszPRJ ) != OGRERR_NONE )
     239                 :                 {
     240                 :                     CPLError( CE_Warning, CPLE_AppDefined, 
     241               0 :                               "Failed to parse PRJ section, ignoring." );
     242               0 :                     delete poSRS;
     243               0 :                     poSRS = NULL;
     244                 :                 }
     245               0 :                 break;
     246                 :             }
     247                 :         }
     248                 :     }
     249               0 :     return poSRS;
     250                 : }

Generated by: LCOV version 1.7