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

       1                 : /******************************************************************************
       2                 :  * $Id: tigerpolychainlink.cpp 10645 2007-01-18 02:22:39Z warmerdam $
       3                 :  *
       4                 :  * Project:  TIGER/Line Translator
       5                 :  * Purpose:  Implements TigerPolyChainLink, providing access to .RTI files.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 1999, Frank Warmerdam
      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: tigerpolychainlink.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
      34                 : 
      35                 : #define FILE_CODE "I"
      36                 : 
      37                 : static TigerFieldInfo rtI_2002_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                 :   { "TLID",       'R', 'N', OFTInteger,   11,  20,  10,       1,   1,     1 },
      42                 :   { "TZIDS",      'R', 'N', OFTInteger,   21,  30,  10,       1,   1,     1 },
      43                 :   { "TZIDE",      'R', 'N', OFTInteger,   31,  40,  10,       1,   1,     1 },
      44                 :   { "CENIDL",     'L', 'A', OFTString,    41,  45,   5,       1,   1,     1 },
      45                 :   { "POLYIDL",    'R', 'N', OFTInteger,   46,  55,  10,       1,   1,     1 },
      46                 :   { "CENIDR",     'L', 'A', OFTString,    56,  60,   5,       1,   1,     1 },
      47                 :   { "POLYIDR",    'R', 'N', OFTInteger,   61,  70,  10,       1,   1,     1 },
      48                 :   { "SOURCE",     'L', 'A', OFTString,    71,  80,  10,       1,   1,     1 },
      49                 :   { "FTSEG",      'L', 'A', OFTString,    81,  97,  17,       1,   1,     1 },
      50                 :   { "RS_I1",      'L', 'A', OFTString,    98, 107,  10,       1,   1,     1 },
      51                 :   { "RS_I2",      'L', 'A', OFTString,   108, 117,  10,       1,   1,     1 },
      52                 :   { "RS_I3",      'L', 'A', OFTString,   118, 127,  10,       1,   1,     1 },
      53                 : };
      54                 : static TigerRecordInfo rtI_2002_info =
      55                 :   {
      56                 :     rtI_2002_fields,
      57                 :     sizeof(rtI_2002_fields) / sizeof(TigerFieldInfo),
      58                 :     127
      59                 :   };
      60                 : 
      61                 : static TigerFieldInfo rtI_fields[] = {
      62                 :   // fieldname    fmt  type OFTType      beg  end  len  bDefine bSet bWrite
      63                 :   { "MODULE",     ' ', ' ', OFTString,     0,   0,   8,       1,   0,     0 },
      64                 :   { "TLID",       'R', 'N', OFTInteger,    6,  15,  10,       1,   1,     1 },
      65                 :   { "FILE",       'L', 'N', OFTString,    16,  20,   5,       1,   1,     1 },
      66                 :   { "STATE",      'L', 'N', OFTInteger,   16,  17,   2,       1,   1,     1 },
      67                 :   { "COUNTY",     'L', 'N', OFTInteger,   18,  20,   3,       1,   1,     1 },
      68                 :   { "RTLINK",     'L', 'A', OFTString,    21,  21,   1,       1,   1,     1 },
      69                 :   { "CENIDL",     'L', 'A', OFTString,    22,  26,   5,       1,   1,     1 },
      70                 :   { "POLYIDL",    'R', 'N', OFTInteger,   27,  36,  10,       1,   1,     1 },
      71                 :   { "CENIDR",     'L', 'A', OFTString,    37,  41,   5,       1,   1,     1 },
      72                 :   { "POLYIDR",    'R', 'N', OFTInteger,   42,  51,  10,       1,   1,     1 }
      73                 : };
      74                 : static TigerRecordInfo rtI_info =
      75                 :   {
      76                 :     rtI_fields,
      77                 :     sizeof(rtI_fields) / sizeof(TigerFieldInfo),
      78                 :     52
      79                 :   };
      80                 : 
      81                 : 
      82                 : /************************************************************************/
      83                 : /*                         TigerPolyChainLink()                         */
      84                 : /************************************************************************/
      85                 : 
      86                 : TigerPolyChainLink::TigerPolyChainLink( OGRTigerDataSource * poDSIn,
      87               0 :                                   const char * pszPrototypeModule )
      88                 : 
      89                 : {
      90               0 :     OGRFieldDefn        oField("",OFTInteger);
      91                 : 
      92               0 :     poDS = poDSIn;
      93               0 :     poFeatureDefn = new OGRFeatureDefn( "PolyChainLink" );
      94               0 :     poFeatureDefn->Reference();
      95               0 :     poFeatureDefn->SetGeomType( wkbNone );
      96                 : 
      97               0 :     if (poDS->GetVersion() >= TIGER_2002) {
      98               0 :       psRTIInfo = &rtI_2002_info;
      99                 :     } else {
     100               0 :       psRTIInfo = &rtI_info;
     101                 :     }
     102                 : 
     103                 :     /* -------------------------------------------------------------------- */
     104                 :     /*      Fields from type I record.                                      */
     105                 :     /* -------------------------------------------------------------------- */
     106                 : 
     107               0 :     AddFieldDefns( psRTIInfo, poFeatureDefn );
     108               0 : }
     109                 : 
     110                 : /************************************************************************/
     111                 : /*                        ~TigerPolyChainLink()                         */
     112                 : /************************************************************************/
     113                 : 
     114               0 : TigerPolyChainLink::~TigerPolyChainLink()
     115                 : 
     116                 : {
     117               0 : }
     118                 : 
     119                 : /************************************************************************/
     120                 : /*                             SetModule()                              */
     121                 : /************************************************************************/
     122                 : 
     123               0 : int TigerPolyChainLink::SetModule( const char * pszModule )
     124                 : 
     125                 : {
     126               0 :     if( !OpenFile( pszModule, FILE_CODE ) )
     127               0 :         return FALSE;
     128                 : 
     129               0 :     EstablishFeatureCount();
     130                 :     
     131               0 :     return TRUE;
     132                 : }
     133                 : 
     134                 : /************************************************************************/
     135                 : /*                             GetFeature()                             */
     136                 : /************************************************************************/
     137                 : 
     138               0 : OGRFeature *TigerPolyChainLink::GetFeature( int nRecordId )
     139                 : 
     140                 : {
     141                 :     char        achRecord[OGR_TIGER_RECBUF_LEN];
     142                 : 
     143               0 :     if( nRecordId < 0 || nRecordId >= nFeatures )
     144                 :     {
     145                 :         CPLError( CE_Failure, CPLE_FileIO,
     146                 :                   "Request for out-of-range feature %d of %sI",
     147               0 :                   nRecordId, pszModule );
     148               0 :         return NULL;
     149                 :     }
     150                 : 
     151                 : /* -------------------------------------------------------------------- */
     152                 : /*      Read the raw record data from the file.                         */
     153                 : /* -------------------------------------------------------------------- */
     154               0 :     if( fpPrimary == NULL )
     155               0 :         return NULL;
     156                 : 
     157               0 :     if( VSIFSeek( fpPrimary, nRecordId * nRecordLength, SEEK_SET ) != 0 )
     158                 :     {
     159                 :         CPLError( CE_Failure, CPLE_FileIO,
     160                 :                   "Failed to seek to %d of %sI",
     161               0 :                   nRecordId * nRecordLength, pszModule );
     162               0 :         return NULL;
     163                 :     }
     164                 : 
     165               0 :     if( VSIFRead( achRecord, psRTIInfo->nRecordLength, 1, fpPrimary ) != 1 )
     166                 :     {
     167                 :         CPLError( CE_Failure, CPLE_FileIO,
     168                 :                   "Failed to read record %d of %sI",
     169               0 :                   nRecordId, pszModule );
     170               0 :         return NULL;
     171                 :     }
     172                 : 
     173                 :     /* -------------------------------------------------------------------- */
     174                 :     /*      Set fields.                                                     */
     175                 :     /* -------------------------------------------------------------------- */
     176                 : 
     177               0 :     OGRFeature  *poFeature = new OGRFeature( poFeatureDefn );
     178                 : 
     179               0 :     SetFields( psRTIInfo, poFeature, achRecord );
     180                 : 
     181               0 :     return poFeature;
     182                 : }
     183                 : 
     184                 : /************************************************************************/
     185                 : /*                           CreateFeature()                            */
     186                 : /************************************************************************/
     187                 : 
     188               0 : OGRErr TigerPolyChainLink::CreateFeature( OGRFeature *poFeature )
     189                 : 
     190                 : {
     191                 :     char        szRecord[OGR_TIGER_RECBUF_LEN];
     192                 : 
     193               0 :     if( !SetWriteModule( FILE_CODE, psRTIInfo->nRecordLength+2, poFeature ) )
     194               0 :         return OGRERR_FAILURE;
     195                 : 
     196               0 :     memset( szRecord, ' ', psRTIInfo->nRecordLength );
     197                 : 
     198               0 :     WriteFields( psRTIInfo, poFeature, szRecord );
     199                 : 
     200               0 :     WriteRecord( szRecord, psRTIInfo->nRecordLength, FILE_CODE );
     201                 : 
     202               0 :     return OGRERR_NONE;
     203                 : }

Generated by: LTP GCOV extension version 1.5