~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/tiger/tigerfilebase.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: tigerfilebase.cpp 17225 2009-06-07 20:59:19Z rouault $
 
2
 * $Id: tigerfilebase.cpp 22961 2011-08-20 17:09:59Z rouault $
3
3
 *
4
4
 * Project:  TIGER/Line Translator
5
5
 * Purpose:  Implements TigerBaseFile class, providing common services to all
33
33
#include "cpl_error.h"
34
34
#include "cpl_string.h"
35
35
 
36
 
CPL_CVSID("$Id: tigerfilebase.cpp 17225 2009-06-07 20:59:19Z rouault $");
 
36
CPL_CVSID("$Id: tigerfilebase.cpp 22961 2011-08-20 17:09:59Z rouault $");
37
37
 
38
38
/************************************************************************/
39
39
/*                           TigerFileBase()                            */
40
40
/************************************************************************/
41
41
 
42
 
TigerFileBase::TigerFileBase()
 
42
TigerFileBase::TigerFileBase( const TigerRecordInfo *psRTInfoIn,
 
43
                              const char            *m_pszFileCodeIn )
43
44
 
44
45
{
45
46
    pszShortModule = NULL;
49
50
    nFeatures = 0;
50
51
    nVersionCode = 0;
51
52
    nVersion = TIGER_Unknown;
 
53
 
 
54
    psRTInfo = psRTInfoIn;
 
55
    m_pszFileCode = m_pszFileCodeIn;
52
56
}
53
57
 
54
58
/************************************************************************/
233
237
/*                              GetField()                              */
234
238
/************************************************************************/
235
239
 
236
 
CPLString TigerFileBase::GetField( const char * pachRawDataRecord,
 
240
const char* TigerFileBase::GetField( const char * pachRawDataRecord,
237
241
                                     int nStartChar, int nEndChar )
238
242
 
239
243
{
248
252
    while( nLength > 0 && aszField[nLength-1] == ' ' )
249
253
        aszField[--nLength] = '\0';
250
254
 
251
 
    return aszField;
 
255
    return CPLSPrintf("%s", aszField);
252
256
}
253
257
 
254
258
/************************************************************************/
304
308
    {
305
309
        strncpy( szValue, poFeature->GetFieldAsString( iField ), 
306
310
                 sizeof(szValue) - 1 );
 
311
        szValue[sizeof(szValue) - 1] = 0;
307
312
        if( (int) strlen(szValue) < nEnd - nStart + 1 )
308
313
            memset( szValue + strlen(szValue), ' ', 
309
314
                    nEnd - nStart + 1 - strlen(szValue) );
440
445
/* -------------------------------------------------------------------- */
441
446
/*      Does this file already exist?                                   */
442
447
/* -------------------------------------------------------------------- */
443
 
    const char *pszFilename;
 
448
    char *pszFilename;
444
449
 
445
450
    pszFilename = poDS->BuildFilename( szFullModule, pszExtension );
446
451
 
447
452
    fpPrimary = VSIFOpen( pszFilename, "ab" );
 
453
    CPLFree(pszFilename);
448
454
    if( fpPrimary == NULL )
449
455
        return FALSE;
450
456
 
456
462
/************************************************************************/
457
463
/*                           AddFieldDefns()                            */
458
464
/************************************************************************/
459
 
void TigerFileBase::AddFieldDefns(TigerRecordInfo *psRTInfo,
 
465
void TigerFileBase::AddFieldDefns(const TigerRecordInfo *psRTInfo,
460
466
                                  OGRFeatureDefn  *poFeatureDefn)
461
467
{
462
468
    OGRFieldDefn        oField("",OFTInteger);
467
473
    
468
474
    for (i=0; i<psRTInfo->nFieldCount; ++i) {
469
475
        if (psRTInfo->pasFields[i].bDefine) {
470
 
            OGRFieldType eFT = psRTInfo->pasFields[i].OGRtype;
 
476
            OGRFieldType eFT = (OGRFieldType)psRTInfo->pasFields[i].OGRtype;
471
477
 
472
478
            if( bLFieldHack 
473
479
                && psRTInfo->pasFields[i].cFmt == 'L' 
485
491
/*                             SetFields()                              */
486
492
/************************************************************************/
487
493
 
488
 
void TigerFileBase::SetFields(TigerRecordInfo *psRTInfo,
 
494
void TigerFileBase::SetFields(const TigerRecordInfo *psRTInfo,
489
495
                              OGRFeature      *poFeature,
490
496
                              char            *achRecord)
491
497
{
504
510
/************************************************************************/
505
511
/*                             WriteField()                             */
506
512
/************************************************************************/
507
 
void TigerFileBase::WriteFields(TigerRecordInfo *psRTInfo,
 
513
void TigerFileBase::WriteFields(const TigerRecordInfo *psRTInfo,
508
514
                                OGRFeature      *poFeature,
509
515
                                char            *szRecord)
510
516
{
521
527
    }
522
528
  }
523
529
}
 
530
 
 
531
 
 
532
 
 
533
/************************************************************************/
 
534
/*                             SetModule()                              */
 
535
/************************************************************************/
 
536
 
 
537
int TigerFileBase::SetModule( const char * pszModule )
 
538
 
 
539
{
 
540
    if (m_pszFileCode == NULL)
 
541
        return FALSE;
 
542
 
 
543
    if( !OpenFile( pszModule, m_pszFileCode ) )
 
544
        return FALSE;
 
545
 
 
546
    EstablishFeatureCount();
 
547
 
 
548
    return TRUE;
 
549
}
 
550
 
 
551
/************************************************************************/
 
552
/*                             GetFeature()                             */
 
553
/************************************************************************/
 
554
 
 
555
OGRFeature *TigerFileBase::GetFeature( int nRecordId )
 
556
 
 
557
{
 
558
    char        achRecord[OGR_TIGER_RECBUF_LEN];
 
559
 
 
560
    if (psRTInfo == NULL)
 
561
        return NULL;
 
562
 
 
563
    if( nRecordId < 0 || nRecordId >= nFeatures )
 
564
    {
 
565
        CPLError( CE_Failure, CPLE_FileIO,
 
566
                  "Request for out-of-range feature %d of %s",
 
567
                  nRecordId, pszModule );
 
568
        return NULL;
 
569
    }
 
570
 
 
571
/* -------------------------------------------------------------------- */
 
572
/*      Read the raw record data from the file.                         */
 
573
/* -------------------------------------------------------------------- */
 
574
    if( fpPrimary == NULL )
 
575
        return NULL;
 
576
 
 
577
    if( VSIFSeek( fpPrimary, nRecordId * nRecordLength, SEEK_SET ) != 0 )
 
578
    {
 
579
        CPLError( CE_Failure, CPLE_FileIO,
 
580
                  "Failed to seek to %d of %s",
 
581
                  nRecordId * nRecordLength, pszModule );
 
582
        return NULL;
 
583
    }
 
584
 
 
585
    if( VSIFRead( achRecord, psRTInfo->nRecordLength, 1, fpPrimary ) != 1 )
 
586
    {
 
587
        CPLError( CE_Failure, CPLE_FileIO,
 
588
                  "Failed to read record %d of %s",
 
589
                  nRecordId, pszModule );
 
590
        return NULL;
 
591
    }
 
592
 
 
593
/* -------------------------------------------------------------------- */
 
594
/*      Set fields.                                                     */
 
595
/* -------------------------------------------------------------------- */
 
596
    OGRFeature  *poFeature = new OGRFeature( poFeatureDefn );
 
597
 
 
598
    SetFields( psRTInfo, poFeature, achRecord );
 
599
 
 
600
    return poFeature;
 
601
}
 
602
 
 
603
/************************************************************************/
 
604
/*                           CreateFeature()                            */
 
605
/************************************************************************/
 
606
 
 
607
OGRErr TigerFileBase::CreateFeature( OGRFeature *poFeature )
 
608
 
 
609
{
 
610
    char        szRecord[OGR_TIGER_RECBUF_LEN];
 
611
 
 
612
    if (psRTInfo == NULL)
 
613
        return OGRERR_FAILURE;
 
614
 
 
615
    if( !SetWriteModule( m_pszFileCode, psRTInfo->nRecordLength+2, poFeature ) )
 
616
        return OGRERR_FAILURE;
 
617
 
 
618
    memset( szRecord, ' ', psRTInfo->nRecordLength );
 
619
 
 
620
    WriteFields( psRTInfo, poFeature, szRecord );
 
621
 
 
622
    WriteRecord( szRecord, psRTInfo->nRecordLength, m_pszFileCode );
 
623
 
 
624
    return OGRERR_NONE;
 
625
}