LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/tiger - tigerpoint.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 37 27 73.0 %
Date: 2011-12-18 Functions: 4 3 75.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: tigerpoint.cpp 22961 2011-08-20 17:09:59Z rouault $
       3                 :  *
       4                 :  * Project:  TIGER/Line Translator
       5                 :  * Purpose:  Implements TigerPoint class.
       6                 :  * Author:   Mark Phillips, mbp@geomtech.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2002, 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: tigerpoint.cpp 22961 2011-08-20 17:09:59Z rouault $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                             TigerPoint()                             */
      37                 : /************************************************************************/
      38              21 : TigerPoint::TigerPoint( int bRequireGeom, const TigerRecordInfo *psRTInfoIn,
      39              21 :                         const char            *m_pszFileCodeIn ) : TigerFileBase(psRTInfoIn, m_pszFileCodeIn)
      40                 : {
      41              21 :     this->bRequireGeom = bRequireGeom;
      42              21 : }
      43                 : 
      44                 : /************************************************************************/
      45                 : /*                             GetFeature()                             */
      46                 : /************************************************************************/
      47           51843 : OGRFeature *TigerPoint::GetFeature( int nRecordId,
      48                 :                                     int nX0, int nX1,
      49                 :                                     int nY0, int nY1 )
      50                 : {
      51                 :     char        achRecord[OGR_TIGER_RECBUF_LEN];
      52                 : 
      53           51843 :     if( nRecordId < 0 || nRecordId >= nFeatures ) {
      54                 :         CPLError( CE_Failure, CPLE_FileIO,
      55                 :                   "Request for out-of-range feature %d of %sP",
      56               0 :                   nRecordId, pszModule );
      57               0 :         return NULL;
      58                 :     }
      59                 : 
      60                 :     /* -------------------------------------------------------------------- */
      61                 :     /*      Read the raw record data from the file.                         */
      62                 :     /* -------------------------------------------------------------------- */
      63                 : 
      64           51843 :     if( fpPrimary == NULL )
      65               0 :         return NULL;
      66                 : 
      67           51843 :     if( VSIFSeek( fpPrimary, nRecordId * nRecordLength, SEEK_SET ) != 0 ) {
      68                 :         CPLError( CE_Failure, CPLE_FileIO,
      69                 :                   "Failed to seek to %d of %sP",
      70               0 :                   nRecordId * nRecordLength, pszModule );
      71               0 :         return NULL;
      72                 :     }
      73                 : 
      74           51843 :     if( VSIFRead( achRecord, psRTInfo->nRecordLength, 1, fpPrimary ) != 1 ) {
      75                 :         CPLError( CE_Failure, CPLE_FileIO,
      76                 :                   "Failed to read record %d of %sP",
      77               0 :                   nRecordId, pszModule );
      78               0 :         return NULL;
      79                 :     }
      80                 : 
      81                 :     /* -------------------------------------------------------------------- */
      82                 :     /*      Set fields.                                                     */
      83                 :     /* -------------------------------------------------------------------- */
      84                 : 
      85           51843 :     OGRFeature  *poFeature = new OGRFeature( poFeatureDefn );
      86                 : 
      87           51843 :     SetFields( psRTInfo, poFeature, achRecord);
      88                 : 
      89                 :     /* -------------------------------------------------------------------- */
      90                 :     /*      Set geometry                                                    */
      91                 :     /* -------------------------------------------------------------------- */
      92                 : 
      93                 :     double      dfX, dfY;
      94                 : 
      95           51843 :     dfX = atoi(GetField(achRecord, nX0, nX1)) / 1000000.0;
      96           51843 :     dfY = atoi(GetField(achRecord, nY0, nY1)) / 1000000.0;
      97                 : 
      98           53208 :     if( dfX != 0.0 || dfY != 0.0 ) {
      99           50478 :         poFeature->SetGeometryDirectly( new OGRPoint( dfX, dfY ) );
     100                 :     }
     101                 :         
     102           51843 :     return poFeature;
     103                 : }
     104                 : 
     105                 : /************************************************************************/
     106                 : /*                           CreateFeature()                            */
     107                 : /************************************************************************/
     108            4711 : OGRErr TigerPoint::CreateFeature( OGRFeature *poFeature, 
     109                 :                                   int pointIndex)
     110                 : 
     111                 : {
     112                 :     char        szRecord[OGR_TIGER_RECBUF_LEN];
     113            4711 :     OGRPoint    *poPoint = (OGRPoint *) poFeature->GetGeometryRef();
     114                 : 
     115            4711 :     if( !SetWriteModule( m_pszFileCode, psRTInfo->nRecordLength+2, poFeature ) )
     116               0 :         return OGRERR_FAILURE;
     117                 : 
     118            4711 :     memset( szRecord, ' ', psRTInfo->nRecordLength );
     119                 : 
     120            4711 :     WriteFields( psRTInfo, poFeature, szRecord );
     121                 : 
     122            9298 :     if( poPoint != NULL 
     123            4587 :         && (poPoint->getGeometryType() == wkbPoint
     124               0 :             || poPoint->getGeometryType() == wkbPoint25D) ) {
     125            4587 :         WritePoint( szRecord, pointIndex, poPoint->getX(), poPoint->getY() );
     126                 :     } else {
     127             124 :         if (bRequireGeom) {
     128               0 :             return OGRERR_FAILURE;
     129                 :         }
     130                 :     }
     131                 : 
     132            4711 :     WriteRecord( szRecord, psRTInfo->nRecordLength, m_pszFileCode );
     133                 : 
     134            4711 :     return OGRERR_NONE;
     135                 : }

Generated by: LCOV version 1.7