LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/tiger - tigerpolygoncorrections.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 38
Code covered: 0.0 % Executed lines: 0

       1                 : /******************************************************************************
       2                 :  * $Id: tigerpolygoncorrections.cpp 10645 2007-01-18 02:22:39Z warmerdam $
       3                 :  *
       4                 :  * Project:  TIGER/Line Translator
       5                 :  * Purpose:  Implements TigerPolygonCorrections, providing access to .RTB files.
       6                 :  * Author:   Mark Phillips, mbp@geomtech.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2002, Frank Warmerdam, Mark Phillips
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #include "ogr_tiger.h"
      31                 : #include "cpl_conv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: tigerpolygoncorrections.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
      34                 : 
      35                 : #define FILE_CODE       "B"
      36                 : 
      37                 : static TigerFieldInfo rtB_fields[] = {
      38                 :   // fieldname    fmt  type OFTType      beg  end  len  bDefine bSet bWrite
      39                 :   { "MODULE",     ' ', ' ', OFTString,     0,   0,   8,       1,   0,     0 },
      40                 :   { "FILE",       'L', 'N', OFTInteger,    6,  10,   5,       1,   1,     1 },
      41                 :   { "CENID",      'L', 'A', OFTString,    11,  15,   5,       1,   1,     1 },
      42                 :   { "POLYID",     'R', 'N', OFTInteger,   16,  25,  10,       1,   1,     1 },
      43                 :   { "STATECQ",    'L', 'N', OFTInteger,   26,  27,   2,       1,   1,     1 },
      44                 :   { "COUNTYCQ",   'L', 'N', OFTInteger,   28,  30,   3,       1,   1,     1 },
      45                 :   { "TRACTCQ",    'L', 'N', OFTInteger,   31,  36,   6,       1,   1,     1 },
      46                 :   { "BLOCKCQ",    'L', 'A', OFTString,    37,  41,   5,       1,   1,     1 },
      47                 :   { "AIANHHFPCQ", 'L', 'N', OFTInteger,   42,  46,   5,       1,   1,     1 },
      48                 :   { "AIANHHCQ",   'L', 'N', OFTInteger,   47,  50,   4,       1,   1,     1 },
      49                 :   { "AIHHTLICQ",  'L', 'A', OFTString,    51,  51,   1,       1,   1,     1 },
      50                 :   { "AITSCECQ",   'L', 'N', OFTInteger,   52,  54,   3,       1,   1,     1 },
      51                 :   { "AITSCQ",     'L', 'N', OFTInteger,   55,  59,   5,       1,   1,     1 },
      52                 :   { "ANRCCQ",     'L', 'N', OFTInteger,   60,  64,   5,       1,   1,     1 },
      53                 :   { "CONCITCQ",   'L', 'N', OFTInteger,   65,  69,   5,       1,   1,     1 },
      54                 :   { "COUSUBCQ",   'L', 'N', OFTInteger,   70,  74,   5,       1,   1,     1 },
      55                 :   { "SUBMCDCQ",   'L', 'N', OFTInteger,   75,  79,   5,       1,   1,     1 },
      56                 :   { "PLACECQ",    'L', 'N', OFTInteger,   80,  84,   5,       1,   1,     1 },
      57                 :   { "UACC",       'L', 'N', OFTInteger,   85,  89,   5,       1,   1,     1 },
      58                 :   { "URCC",       'L', 'A', OFTString,    90,  90,   1,       1,   1,     1 },
      59                 :   { "RS-B1",      'L', 'A', OFTString,    91,  98,  12,       1,   1,     1 },
      60                 : };
      61                 : static TigerRecordInfo rtB_info =
      62                 :   {
      63                 :     rtB_fields,
      64                 :     sizeof(rtB_fields) / sizeof(TigerFieldInfo),
      65                 :     98
      66                 :   };
      67                 : 
      68                 : /************************************************************************/
      69                 : /*                     TigerPolygonCorrections()                        */
      70                 : /************************************************************************/
      71                 : 
      72                 : TigerPolygonCorrections::TigerPolygonCorrections( OGRTigerDataSource * poDSIn,
      73               0 :                               const char * pszPrototypeModule )
      74                 : 
      75                 : {
      76               0 :     OGRFieldDefn        oField("",OFTInteger);
      77                 : 
      78               0 :     poDS = poDSIn;
      79               0 :     poFeatureDefn = new OGRFeatureDefn( "PolygonCorrections" );
      80               0 :     poFeatureDefn->Reference();
      81               0 :     poFeatureDefn->SetGeomType( wkbNone );
      82                 : 
      83               0 :     psRTBInfo = &rtB_info;
      84                 : 
      85                 :     /* -------------------------------------------------------------------- */
      86                 :     /*      Fields from type B record.                                      */
      87                 :     /* -------------------------------------------------------------------- */
      88                 : 
      89               0 :     AddFieldDefns( psRTBInfo, poFeatureDefn );
      90               0 : }
      91                 : 
      92                 : /************************************************************************/
      93                 : /*                           ~TigerPolygonCorrections()                           */
      94                 : /************************************************************************/
      95                 : 
      96               0 : TigerPolygonCorrections::~TigerPolygonCorrections()
      97                 : 
      98                 : {
      99               0 : }
     100                 : 
     101                 : /************************************************************************/
     102                 : /*                             SetModule()                              */
     103                 : /************************************************************************/
     104                 : 
     105               0 : int TigerPolygonCorrections::SetModule( const char * pszModule )
     106                 : 
     107                 : {
     108               0 :     if( !OpenFile( pszModule, FILE_CODE ) )
     109               0 :         return FALSE;
     110                 : 
     111               0 :     EstablishFeatureCount();
     112                 :     
     113               0 :     return TRUE;
     114                 : }
     115                 : 
     116                 : /************************************************************************/
     117                 : /*                             GetFeature()                             */
     118                 : /************************************************************************/
     119                 : 
     120               0 : OGRFeature *TigerPolygonCorrections::GetFeature( int nRecordId )
     121                 : 
     122                 : {
     123                 :     char        achRecord[OGR_TIGER_RECBUF_LEN];
     124                 : 
     125               0 :     if( nRecordId < 0 || nRecordId >= nFeatures )
     126                 :     {
     127                 :         CPLError( CE_Failure, CPLE_FileIO,
     128                 :                   "Request for out-of-range feature %d of %sZ",
     129               0 :                   nRecordId, pszModule );
     130               0 :         return NULL;
     131                 :     }
     132                 : 
     133                 : /* -------------------------------------------------------------------- */
     134                 : /*      Read the raw record data from the file.                         */
     135                 : /* -------------------------------------------------------------------- */
     136               0 :     if( fpPrimary == NULL )
     137               0 :         return NULL;
     138                 : 
     139               0 :     if( VSIFSeek( fpPrimary, nRecordId * nRecordLength, SEEK_SET ) != 0 )
     140                 :     {
     141                 :         CPLError( CE_Failure, CPLE_FileIO,
     142                 :                   "Failed to seek to %d of %sZ",
     143               0 :                   nRecordId * nRecordLength, pszModule );
     144               0 :         return NULL;
     145                 :     }
     146                 : 
     147               0 :     if( VSIFRead( achRecord, psRTBInfo->nRecordLength, 1, fpPrimary ) != 1 )
     148                 :     {
     149                 :         CPLError( CE_Failure, CPLE_FileIO,
     150                 :                   "Failed to read record %d of %sZ",
     151               0 :                   nRecordId, pszModule );
     152               0 :         return NULL;
     153                 :     }
     154                 : 
     155                 :     /* -------------------------------------------------------------------- */
     156                 :     /*      Set fields.                                                     */
     157                 :     /* -------------------------------------------------------------------- */
     158                 : 
     159               0 :     OGRFeature  *poFeature = new OGRFeature( poFeatureDefn );
     160                 : 
     161               0 :     SetFields( psRTBInfo, poFeature, achRecord );
     162                 : 
     163               0 :     return poFeature;
     164                 : }
     165                 : 
     166                 : /************************************************************************/
     167                 : /*                           CreateFeature()                            */
     168                 : /************************************************************************/
     169                 : 
     170               0 : OGRErr TigerPolygonCorrections::CreateFeature( OGRFeature *poFeature )
     171                 : 
     172                 : {
     173                 :     char        szRecord[OGR_TIGER_RECBUF_LEN];
     174                 : 
     175               0 :     if( !SetWriteModule( FILE_CODE, psRTBInfo->nRecordLength+2, poFeature ) )
     176               0 :         return OGRERR_FAILURE;
     177                 : 
     178               0 :     memset( szRecord, ' ', psRTBInfo->nRecordLength );
     179                 : 
     180               0 :     WriteFields( psRTBInfo, poFeature, szRecord);
     181                 : 
     182               0 :     WriteRecord( szRecord, psRTBInfo->nRecordLength, FILE_CODE );
     183                 : 
     184               0 :     return OGRERR_NONE;
     185                 : }

Generated by: LTP GCOV extension version 1.5