LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/avc - ogravce00datasource.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 59 40 67.8 %
Date: 2010-01-09 Functions: 8 6 75.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogravce00datasource.cpp 10645 2007-01-18 02:22:39Z 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 10645 2007-01-18 02:22:39Z warmerdam $");
      37                 : 
      38                 : /************************************************************************/
      39                 : /*                        OGRAVCE00DataSource()                         */
      40                 : /************************************************************************/
      41                 : 
      42              51 : OGRAVCE00DataSource::OGRAVCE00DataSource()
      43              51 :     : nLayers(0), pszName(NULL), psE00(NULL), papoLayers(NULL)
      44                 : {
      45              51 : }
      46                 : 
      47                 : /************************************************************************/
      48                 : /*                        ~OGRAVCE00DataSource()                        */
      49                 : /************************************************************************/
      50                 : 
      51             102 : OGRAVCE00DataSource::~OGRAVCE00DataSource()
      52                 : 
      53                 : {
      54              51 :     if( psE00 )
      55                 :     {
      56               1 :         AVCE00ReadCloseE00( psE00 );
      57               1 :         psE00 = NULL;
      58                 :     }
      59                 : 
      60              51 :     CPLFree( pszName );
      61                 : 
      62              53 :     for( int i = 0; i < nLayers; i++ )
      63               2 :         delete papoLayers[i];
      64                 :     
      65              51 :     CPLFree( papoLayers );
      66             102 : }
      67                 : 
      68                 : /************************************************************************/
      69                 : /*                                Open()                                */
      70                 : /************************************************************************/
      71                 : 
      72              51 : 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              51 :     if( bTestOpen )
      80              51 :         CPLPushErrorHandler( CPLQuietErrorHandler );
      81                 : 
      82              51 :     psE00 = AVCE00ReadOpenE00(pszNewName);
      83                 : 
      84              51 :     if( bTestOpen )
      85                 :     {
      86              51 :         CPLPopErrorHandler();
      87              51 :         CPLErrorReset();
      88                 :     }
      89                 : 
      90              51 :     if( psE00 == NULL )
      91              50 :         return FALSE;
      92                 : 
      93               1 :     pszName = CPLStrdup( pszNewName );
      94                 :     /* pszCoverageName = CPLStrdup( psE00->pszCoverName ); */
      95               1 :     pszCoverageName = CPLStrdup( pszNewName );
      96                 : 
      97                 : /* -------------------------------------------------------------------- */
      98                 : /*      Create layers for the "interesting" sections of the coverage.   */
      99                 : /* -------------------------------------------------------------------- */
     100                 :     int iSection;
     101                 : 
     102                 :     papoLayers = (OGRAVCE00Layer **)
     103               1 :         CPLCalloc( sizeof(OGRAVCE00Layer *), psE00->numSections );
     104               1 :     nLayers = 0;
     105                 : 
     106               8 :     for( iSection = 0; iSection < psE00->numSections; iSection++ )
     107                 :     {
     108               7 :         AVCE00Section *psSec = psE00->pasSections + iSection;
     109                 : 
     110               7 :         switch( psSec->eType )
     111                 :         {
     112                 :           case AVCFileARC:
     113                 :           case AVCFilePAL:
     114                 :           case AVCFileCNT:
     115                 :           case AVCFileLAB:
     116                 :           case AVCFileRPL:
     117                 :           case AVCFileTXT:
     118               2 :             papoLayers[nLayers++] = new OGRAVCE00Layer( this, psSec );
     119               2 :             break;
     120                 : 
     121                 :           case AVCFileTX6:
     122               0 :             break;
     123                 : 
     124                 :           case AVCFileTABLE:
     125               4 :             CheckAddTable(psSec);
     126                 :             break;
     127                 : 
     128                 :           case AVCFilePRJ:
     129                 :           {
     130                 : #if 0
     131                 :               poSRS = new OGRSpatialReference();
     132                 :               char  **papszPRJ;
     133                 :               AVCE00File *hFile;
     134                 :               
     135                 :               hFile = AVCE00ReadOpen(psE00->pszCoverPath, 
     136                 :                                      psSec->pszFilename, 
     137                 :                                      psE00->eCoverType, 
     138                 :                                      psSec->eType,
     139                 :                                      psE00->psDBCSInfo);
     140                 :               if( hFile && poSRS == NULL )
     141                 :               {
     142                 :                   papszPRJ = AVCE00ReadNextPrj( hFile );
     143                 : 
     144                 :                   poSRS = new OGRSpatialReference();
     145                 :                   if( poSRS->importFromESRI( papszPRJ ) != OGRERR_NONE )
     146                 :                   {
     147                 :                       CPLError( CE_Warning, CPLE_AppDefined, 
     148                 :                                 "Failed to parse PRJ section, ignoring." );
     149                 :                       delete poSRS;
     150                 :                       poSRS = NULL;
     151                 :                   }
     152                 :                   AVCE00ReadClose( hFile );
     153                 :               }
     154                 : #endif
     155                 :           }
     156                 :           break;
     157                 : 
     158                 :           default:
     159                 :             ;
     160                 :         }
     161                 :     }
     162                 :     
     163               1 :     return nLayers > 0;
     164                 : }
     165                 : 
     166               4 : int OGRAVCE00DataSource::CheckAddTable( AVCE00Section *psTblSection )
     167                 : {
     168               4 :     int i, nCount = 0;
     169              12 :     for (i = 0; i < nLayers; ++i)
     170                 :     {
     171               8 :         if (papoLayers[i]->CheckSetupTable(psTblSection))
     172               0 :             ++nCount;
     173                 :     }
     174               4 :     return nCount;
     175                 : }
     176                 : 
     177                 : /************************************************************************/
     178                 : /*                           TestCapability()                           */
     179                 : /************************************************************************/
     180                 : 
     181               0 : int OGRAVCE00DataSource::TestCapability( const char * pszCap )
     182                 : 
     183                 : {
     184               0 :     return FALSE;
     185                 : }
     186                 : 
     187                 : /************************************************************************/
     188                 : /*                              GetLayer()                              */
     189                 : /************************************************************************/
     190                 : 
     191               1 : OGRLayer *OGRAVCE00DataSource::GetLayer( int iLayer )
     192                 : 
     193                 : {
     194               1 :     if( iLayer < 0 || iLayer >= nLayers )
     195               0 :         return NULL;
     196                 :     else
     197               1 :         return papoLayers[iLayer];
     198                 : }
     199                 : 
     200                 : /************************************************************************/
     201                 : /*                           GetSpatialRef()                            */
     202                 : /************************************************************************/
     203               0 : OGRSpatialReference *OGRAVCE00DataSource::GetSpatialRef()
     204                 : {
     205               0 :     if (NULL == poSRS && psE00 != NULL)
     206                 :     /* if (psE00 != NULL) */
     207                 :     {
     208                 :         int iSection;
     209                 :         AVCE00Section *psSec;
     210                 :         char **pszPRJ;
     211                 : 
     212               0 :         for( iSection = 0; iSection < psE00->numSections; iSection++ )
     213                 :         {
     214               0 :             psSec = psE00->pasSections + iSection;
     215               0 :             if (psSec->eType == AVCFilePRJ)
     216                 :             {
     217               0 :             AVCE00ReadGotoSectionE00(psE00, psSec, 0);
     218               0 :               pszPRJ = (char **)AVCE00ReadNextObjectE00(psE00);
     219               0 :                 poSRS = new OGRSpatialReference();
     220               0 :                 if( poSRS->importFromESRI( pszPRJ ) != OGRERR_NONE )
     221                 :                 {
     222                 :                     CPLError( CE_Warning, CPLE_AppDefined, 
     223               0 :                               "Failed to parse PRJ section, ignoring." );
     224               0 :                     delete poSRS;
     225               0 :                     poSRS = NULL;
     226                 :                 }
     227               0 :                 break;
     228                 :             }
     229                 :         }
     230                 :     }
     231               0 :     return poSRS;
     232                 : }

Generated by: LCOV version 1.7