LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/tiger - ogr_tiger.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 2 18 11.1 %
Date: 2025-01-18 12:42:00 Functions: 1 9 11.1 %

          Line data    Source code
       1             : /*-*-C++-*-*/
       2             : /******************************************************************************
       3             :  *
       4             :  * Project:  TIGER/Line Translator
       5             :  * Purpose:  Main declarations for Tiger translator.
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 1999, Frank Warmerdam
      10             :  * Copyright (c) 2008-2011, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * SPDX-License-Identifier: MIT
      13             :  ****************************************************************************/
      14             : 
      15             : #ifndef OGR_TIGER_H_INCLUDED
      16             : #define OGR_TIGER_H_INCLUDED
      17             : 
      18             : #include "cpl_conv.h"
      19             : #include "ogrsf_frmts.h"
      20             : 
      21             : class OGRTigerDataSource;
      22             : 
      23             : /*
      24             : ** TIGER Versions
      25             : **
      26             : ** 0000           TIGER/Line Precensus Files, 1990
      27             : ** 0002           TIGER/Line Initial Voting District Codes Files, 1990
      28             : ** 0003           TIGER/Line Files, 1990
      29             : ** 0005           TIGER/Line Files, 1992
      30             : ** 0021           TIGER/Line Files, 1994
      31             : ** 0024           TIGER/Line Files, 1995
      32             : ** 0697 to 1098   TIGER/Line Files, 1997
      33             : ** 1298 to 0499   TIGER/Line Files, 1998
      34             : ** 0600 to 0800   TIGER/Line Files, 1999
      35             : ** 1000 to 1100   TIGER/Line Files, Redistricting Census 2000
      36             : ** 0301 to 0801   TIGER/Line Files, Census 2000
      37             : **
      38             : ** 0302 to 0502   TIGER/Line Files, UA 2000
      39             : ** ????    ????
      40             : **
      41             : ** 0602  & higher TIGER/Line Files, 2002
      42             : ** ????    ????
      43             : */
      44             : 
      45             : typedef enum
      46             : {
      47             :     TIGER_1990_Precensus = 0,
      48             :     TIGER_1990 = 1,
      49             :     TIGER_1992 = 2,
      50             :     TIGER_1994 = 3,
      51             :     TIGER_1995 = 4,
      52             :     TIGER_1997 = 5,
      53             :     TIGER_1998 = 6,
      54             :     TIGER_1999 = 7,
      55             :     TIGER_2000_Redistricting = 8,
      56             :     TIGER_2000_Census = 9,
      57             :     TIGER_UA2000 = 10,
      58             :     TIGER_2002 = 11,
      59             :     TIGER_2003 = 12,
      60             :     TIGER_2004 = 13,
      61             :     TIGER_Unknown
      62             : } TigerVersion;
      63             : 
      64             : TigerVersion TigerClassifyVersion(int);
      65             : const char *TigerVersionString(TigerVersion);
      66             : 
      67             : /*****************************************************************************/
      68             : /* The TigerFieldInfo and TigerRecordInfo structures hold information about  */
      69             : /* the schema of a TIGER record type.  In each layer implementation file     */
      70             : /* there are statically initialized variables of these types that describe    */
      71             : /* the record types associated with that layer.  In the case where different */
      72             : /* TIGER versions have different schemas, there is a                         */
      73             : /* TigerFieldInfo/TigerRecordInfo for each version, and the constructor      */
      74             : /* for the layer chooses a pointer to the correct set based on the version.  */
      75             : /*****************************************************************************/
      76             : 
      77             : typedef struct TigerFieldInfo
      78             : {
      79             :     char pszFieldName[11];  // name of the field
      80             :     char cFmt;              // format of the field ('L' or 'R')
      81             :     char cType;             // type of the field ('A' or 'N')
      82             :     char OGRtype;        // OFTType of the field (OFTInteger, OFTString, ...?)
      83             :     unsigned char nBeg;  // beginning column number for field
      84             :     unsigned char nEnd;  // ending column number for field
      85             :     unsigned char nLen;  // length of field
      86             : 
      87             :     unsigned int bDefine : 1;  // whether to add this field to the FeatureDefn
      88             :     unsigned int bSet : 1;     // whether to set this field in GetFeature()
      89             : } TigerFieldInfo;
      90             : 
      91             : typedef struct TigerRecordInfo
      92             : {
      93             :     const TigerFieldInfo *pasFields;
      94             :     unsigned char nFieldCount;
      95             :     unsigned char nRecordLength;
      96             : } TigerRecordInfo;
      97             : 
      98             : // OGR_TIGER_RECBUF_LEN should be a number that is larger than the
      99             : // longest possible record length for any record type; it is used to
     100             : // create arrays to hold the records.  At the time of this writing the
     101             : // longest record (RT1) has length 228, but I'm choosing 500 because
     102             : // it is a good round number and will allow for growth without having
     103             : // to modify this file.  The code never holds more than a few records
     104             : // in memory at a time, so having OGR_TIGER_RECBUF_LEN be much larger
     105             : // than is really necessary won't affect the amount of memory required
     106             : // in a substantial way.
     107             : // mbp Fri Dec 20 19:19:59 2002
     108             : // Note: OGR_TIGER_RECBUF_LEN should also be larger than 255, since
     109             : // TigerRecordInfo::nRecordLength fits on unsigned char.
     110             : #define OGR_TIGER_RECBUF_LEN 500
     111             : 
     112             : /************************************************************************/
     113             : /*                            TigerFileBase                             */
     114             : /************************************************************************/
     115             : 
     116             : class TigerFileBase CPL_NON_FINAL
     117             : {
     118             :   protected:
     119             :     OGRTigerDataSource *poDS;
     120             : 
     121             :     char *pszModule;
     122             :     char *pszShortModule;
     123             :     VSILFILE *fpPrimary;
     124             : 
     125             :     OGRFeatureDefn *poFeatureDefn;
     126             : 
     127             :     int nFeatures;
     128             :     int nRecordLength;
     129             : 
     130             :     int OpenFile(const char *, const char *);
     131             :     void EstablishFeatureCount();
     132             : 
     133             :     static int EstablishRecordLength(VSILFILE *);
     134             : 
     135             :     void SetupVersion();
     136             : 
     137             :     int nVersionCode;
     138             :     TigerVersion nVersion;
     139             : 
     140             :   public:
     141             :     explicit TigerFileBase(const TigerRecordInfo *psRTInfoIn = nullptr,
     142             :                            const char *m_pszFileCodeIn = nullptr);
     143             :     virtual ~TigerFileBase();
     144             : 
     145             :     TigerVersion GetVersion()
     146             :     {
     147             :         return nVersion;
     148             :     }
     149             : 
     150             :     int GetVersionCode()
     151             :     {
     152             :         return nVersionCode;
     153             :     }
     154             : 
     155           0 :     virtual const char *GetShortModule()
     156             :     {
     157           0 :         return pszShortModule;
     158             :     }
     159             : 
     160           0 :     virtual const char *GetModule()
     161             :     {
     162           0 :         return pszModule;
     163             :     }
     164             : 
     165           0 :     virtual int GetFeatureCount()
     166             :     {
     167           0 :         return nFeatures;
     168             :     }
     169             : 
     170           0 :     OGRFeatureDefn *GetFeatureDefn()
     171             :     {
     172           0 :         return poFeatureDefn;
     173             :     }
     174             : 
     175             :     static const char *GetField(const char *, int, int);
     176             :     static void SetField(OGRFeature *, const char *, const char *, int, int);
     177             : 
     178             :     virtual bool SetModule(const char *pszModule);
     179             :     virtual OGRFeature *GetFeature(int nRecordId);
     180             : 
     181             :   protected:
     182             :     static void AddFieldDefns(const TigerRecordInfo *psRTInfo,
     183             :                               OGRFeatureDefn *poFeatureDefn);
     184             : 
     185             :     static void SetFields(const TigerRecordInfo *psRTInfo,
     186             :                           OGRFeature *poFeature, char *achRecord);
     187             : 
     188             :     const TigerRecordInfo *psRTInfo;
     189             :     const char *m_pszFileCode;
     190             : };
     191             : 
     192             : /************************************************************************/
     193             : /*                          TigerCompleteChain                          */
     194             : /************************************************************************/
     195             : 
     196             : class TigerCompleteChain final : public TigerFileBase
     197             : {
     198             :     VSILFILE *fpShape;
     199             :     int *panShapeRecordId;
     200             : 
     201             :     VSILFILE *fpRT3;
     202             :     bool bUsingRT3;
     203             :     int nRT1RecOffset;
     204             : 
     205             :     int GetShapeRecordId(int, int);
     206             :     bool AddShapePoints(int, int, OGRLineString *, int);
     207             : 
     208             :     void AddFieldDefnsPre2002();
     209             :     OGRFeature *GetFeaturePre2002(int);
     210             : 
     211             :     OGRFeature *GetFeature2002(int);
     212             :     void AddFieldDefns2002();
     213             : 
     214             :     const TigerRecordInfo *psRT1Info;
     215             :     const TigerRecordInfo *psRT2Info;
     216             :     const TigerRecordInfo *psRT3Info;
     217             : 
     218             :   public:
     219             :     TigerCompleteChain(OGRTigerDataSource *, const char *);
     220             :     virtual ~TigerCompleteChain();
     221             : 
     222             :     virtual bool SetModule(const char *) override;
     223             : 
     224             :     virtual OGRFeature *GetFeature(int) override;
     225             : };
     226             : 
     227             : /************************************************************************/
     228             : /*                    TigerAltName (Type 4 records)                     */
     229             : /************************************************************************/
     230             : 
     231             : class TigerAltName final : public TigerFileBase
     232             : {
     233             :   public:
     234             :     TigerAltName(OGRTigerDataSource *, const char *);
     235             : 
     236             :     virtual OGRFeature *GetFeature(int) override;
     237             : };
     238             : 
     239             : /************************************************************************/
     240             : /*                    TigerFeatureIds (Type 5 records)                  */
     241             : /************************************************************************/
     242             : 
     243             : class TigerFeatureIds final : public TigerFileBase
     244             : {
     245             :   public:
     246             :     TigerFeatureIds(OGRTigerDataSource *, const char *);
     247             : };
     248             : 
     249             : /************************************************************************/
     250             : /*                    TigerZipCodes (Type 6 records)                    */
     251             : /************************************************************************/
     252             : 
     253             : class TigerZipCodes final : public TigerFileBase
     254             : {
     255             :   public:
     256             :     TigerZipCodes(OGRTigerDataSource *, const char *);
     257             : };
     258             : 
     259             : /************************************************************************/
     260             : /*                    TigerPoint                                        */
     261             : /* This is an abstract base class for TIGER layers with point geometry. */
     262             : /* Since much of the implementation of these layers is similar, I've    */
     263             : /* put it into this base class to avoid duplication in the actual       */
     264             : /* layer classes.  mbp Sat Jan  4 16:41:19 2003.                        */
     265             : /************************************************************************/
     266             : 
     267             : class TigerPoint CPL_NON_FINAL : public TigerFileBase
     268             : {
     269             :   protected:
     270             :     explicit TigerPoint(const TigerRecordInfo *psRTInfoIn = nullptr,
     271             :                         const char *m_pszFileCodeIn = nullptr);
     272             : 
     273             :   public:
     274           0 :     virtual OGRFeature *GetFeature(int nFID) override
     275             :     {
     276           0 :         return TigerFileBase::GetFeature(nFID);
     277             :     } /* to avoid -Woverloaded-virtual warnings */
     278             : 
     279             :     OGRFeature *GetFeature(int nRecordId, int nX0, int nX1, int nY0, int nY1);
     280             : };
     281             : 
     282             : /************************************************************************/
     283             : /*                   TigerLandmarks (Type 7 records)                    */
     284             : /************************************************************************/
     285             : 
     286             : class TigerLandmarks final : public TigerPoint
     287             : {
     288             :   public:
     289             :     TigerLandmarks(OGRTigerDataSource *, const char *);
     290             : 
     291             :     virtual OGRFeature *GetFeature(int) override;
     292             : };
     293             : 
     294             : /************************************************************************/
     295             : /*                   TigerAreaLandmarks (Type 8 records)                */
     296             : /************************************************************************/
     297             : 
     298             : class TigerAreaLandmarks final : public TigerFileBase
     299             : {
     300             :   public:
     301             :     TigerAreaLandmarks(OGRTigerDataSource *, const char *);
     302             : };
     303             : 
     304             : /************************************************************************/
     305             : /*                   TigerKeyFeatures (Type 9 records)                  */
     306             : /************************************************************************/
     307             : 
     308             : class TigerKeyFeatures final : public TigerFileBase
     309             : {
     310             :   public:
     311             :     TigerKeyFeatures(OGRTigerDataSource *, const char *);
     312             : };
     313             : 
     314             : /************************************************************************/
     315             : /*                   TigerPolygon (Type A&S records)                    */
     316             : /************************************************************************/
     317             : 
     318             : class TigerPolygon final : public TigerFileBase
     319             : {
     320             :   private:
     321             :     const TigerRecordInfo *psRTAInfo;
     322             :     const TigerRecordInfo *psRTSInfo;
     323             : 
     324             :     VSILFILE *fpRTS;
     325             :     bool bUsingRTS;
     326             :     int nRTSRecLen;
     327             : 
     328             :   public:
     329             :     TigerPolygon(OGRTigerDataSource *, const char *);
     330             :     virtual ~TigerPolygon();
     331             : 
     332             :     virtual bool SetModule(const char *) override;
     333             : 
     334             :     virtual OGRFeature *GetFeature(int) override;
     335             : };
     336             : 
     337             : /************************************************************************/
     338             : /*                    TigerPolygonCorrections (Type B records)          */
     339             : /************************************************************************/
     340             : 
     341             : class TigerPolygonCorrections final : public TigerFileBase
     342             : {
     343             :   public:
     344             :     TigerPolygonCorrections(OGRTigerDataSource *, const char *);
     345             : };
     346             : 
     347             : /************************************************************************/
     348             : /*                  TigerEntityNames (Type C records)                   */
     349             : /************************************************************************/
     350             : 
     351             : class TigerEntityNames final : public TigerFileBase
     352             : {
     353             :   public:
     354             :     TigerEntityNames(OGRTigerDataSource *, const char *);
     355             : };
     356             : 
     357             : /************************************************************************/
     358             : /*                    TigerPolygonEconomic (Type E records)             */
     359             : /************************************************************************/
     360             : 
     361             : class TigerPolygonEconomic final : public TigerFileBase
     362             : {
     363             :   public:
     364             :     TigerPolygonEconomic(OGRTigerDataSource *, const char *);
     365             : };
     366             : 
     367             : /************************************************************************/
     368             : /*                  TigerIDHistory (Type H records)                     */
     369             : /************************************************************************/
     370             : 
     371             : class TigerIDHistory final : public TigerFileBase
     372             : {
     373             :   public:
     374             :     TigerIDHistory(OGRTigerDataSource *, const char *);
     375             : };
     376             : 
     377             : /************************************************************************/
     378             : /*                   TigerPolyChainLink (Type I records)                */
     379             : /************************************************************************/
     380             : 
     381             : class TigerPolyChainLink final : public TigerFileBase
     382             : {
     383             :   public:
     384             :     TigerPolyChainLink(OGRTigerDataSource *, const char *);
     385             : };
     386             : 
     387             : /************************************************************************/
     388             : /*                TigerSpatialMetadata (Type M records)                 */
     389             : /************************************************************************/
     390             : 
     391             : class TigerSpatialMetadata final : public TigerFileBase
     392             : {
     393             :   public:
     394             :     TigerSpatialMetadata(OGRTigerDataSource *, const char *);
     395             : };
     396             : 
     397             : /************************************************************************/
     398             : /*                   TigerPIP (Type P records)                          */
     399             : /************************************************************************/
     400             : 
     401             : class TigerPIP final : public TigerPoint
     402             : {
     403             :   public:
     404             :     TigerPIP(OGRTigerDataSource *, const char *);
     405             : 
     406             :     virtual OGRFeature *GetFeature(int) override;
     407             : };
     408             : 
     409             : /************************************************************************/
     410             : /*                   TigerTLIDRange (Type R records)                    */
     411             : /************************************************************************/
     412             : 
     413             : class TigerTLIDRange final : public TigerFileBase
     414             : {
     415             :   public:
     416             :     TigerTLIDRange(OGRTigerDataSource *, const char *);
     417             : };
     418             : 
     419             : /************************************************************************/
     420             : /*                    TigerZeroCellID (Type T records)                  */
     421             : /************************************************************************/
     422             : 
     423             : class TigerZeroCellID final : public TigerFileBase
     424             : {
     425             :   public:
     426             :     TigerZeroCellID(OGRTigerDataSource *, const char *);
     427             : };
     428             : 
     429             : /************************************************************************/
     430             : /*                    TigerOverUnder (Type U records)                   */
     431             : /************************************************************************/
     432             : 
     433             : class TigerOverUnder final : public TigerPoint
     434             : {
     435             :   public:
     436             :     TigerOverUnder(OGRTigerDataSource *, const char *);
     437             : 
     438             :     virtual OGRFeature *GetFeature(int) override;
     439             : };
     440             : 
     441             : /************************************************************************/
     442             : /*                    TigerZipPlus4 (Type Z records)                    */
     443             : /************************************************************************/
     444             : 
     445             : class TigerZipPlus4 final : public TigerFileBase
     446             : {
     447             :   public:
     448             :     TigerZipPlus4(OGRTigerDataSource *, const char *);
     449             : };
     450             : 
     451             : /************************************************************************/
     452             : /*                            OGRTigerLayer                             */
     453             : /************************************************************************/
     454             : 
     455             : class OGRTigerLayer final : public OGRLayer
     456             : {
     457             :     TigerFileBase *poReader;
     458             : 
     459             :     OGRTigerDataSource *poDS;
     460             : 
     461             :     int nFeatureCount;
     462             :     int *panModuleFCount;
     463             :     int *panModuleOffset;
     464             : 
     465             :     int iLastFeatureId;
     466             :     int iLastModule;
     467             : 
     468             :   public:
     469             :     OGRTigerLayer(OGRTigerDataSource *poDS, TigerFileBase *);
     470             :     virtual ~OGRTigerLayer();
     471             : 
     472             :     void ResetReading() override;
     473             :     OGRFeature *GetNextFeature() override;
     474             :     OGRFeature *GetFeature(GIntBig nFeatureId) override;
     475             : 
     476             :     OGRFeatureDefn *GetLayerDefn() override;
     477             : 
     478             :     GIntBig GetFeatureCount(int) override;
     479             : 
     480             :     int TestCapability(const char *) override;
     481             : };
     482             : 
     483             : /************************************************************************/
     484             : /*                          OGRTigerDataSource                          */
     485             : /************************************************************************/
     486             : 
     487             : class OGRTigerDataSource final : public GDALDataset
     488             : {
     489             :     int nLayers;
     490             :     OGRTigerLayer **papoLayers;
     491             : 
     492             :     OGRSpatialReference *poSpatialRef;
     493             : 
     494             :     char **papszOptions;
     495             : 
     496             :     char *pszPath;
     497             : 
     498             :     int nModules;
     499             :     char **papszModules;
     500             : 
     501             :     int nVersionCode;
     502             :     TigerVersion nVersion;
     503             : 
     504             :     TigerVersion TigerCheckVersion(TigerVersion, const char *);
     505             : 
     506             :     CPL_DISALLOW_COPY_ASSIGN(OGRTigerDataSource)
     507             : 
     508             :   public:
     509             :     OGRTigerDataSource();
     510             :     virtual ~OGRTigerDataSource();
     511             : 
     512           0 :     TigerVersion GetVersion() const
     513             :     {
     514           0 :         return nVersion;
     515             :     }
     516             : 
     517             :     int GetVersionCode() const
     518             :     {
     519             :         return nVersionCode;
     520             :     }
     521             : 
     522             :     const char *GetOption(const char *);
     523             : 
     524             :     int Open(const char *pszName, int bTestOpen = FALSE,
     525             :              char **papszFileList = nullptr);
     526             : 
     527             :     int GetLayerCount() override;
     528             :     OGRLayer *GetLayer(int) override;
     529             :     OGRLayer *GetLayer(const char *pszLayerName);
     530             : 
     531             :     void AddLayer(OGRTigerLayer *);
     532             : 
     533           0 :     OGRSpatialReference *DSGetSpatialRef()
     534             :     {
     535           0 :         return poSpatialRef;
     536             :     }
     537             : 
     538          72 :     const char *GetDirPath()
     539             :     {
     540          72 :         return pszPath;
     541             :     }
     542             : 
     543             :     char *BuildFilename(const char *pszModule, const char *pszExtension);
     544             : 
     545           0 :     int GetModuleCount() const
     546             :     {
     547           0 :         return nModules;
     548             :     }
     549             : 
     550             :     const char *GetModule(int);
     551             :     bool CheckModule(const char *pszModule);
     552             :     void AddModule(const char *pszModule);
     553             : };
     554             : 
     555             : #endif /* ndef OGR_TIGER_H_INCLUDED */

Generated by: LCOV version 1.14