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 29 6.9 %
Date: 2026-03-26 23:25:44 Functions: 1 34 2.9 %

          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             :     CPL_DISALLOW_COPY_ASSIGN(TigerFileBase)
     192             : };
     193             : 
     194             : /************************************************************************/
     195             : /*                          TigerCompleteChain                          */
     196             : /************************************************************************/
     197             : 
     198             : class TigerCompleteChain final : public TigerFileBase
     199             : {
     200             :     VSILFILE *fpShape;
     201             :     int *panShapeRecordId;
     202             : 
     203             :     VSILFILE *fpRT3;
     204             :     bool bUsingRT3;
     205             :     int nRT1RecOffset;
     206             : 
     207             :     int GetShapeRecordId(int, int);
     208             :     bool AddShapePoints(int, int, OGRLineString *, int);
     209             : 
     210             :     void AddFieldDefnsPre2002();
     211             :     OGRFeature *GetFeaturePre2002(int);
     212             : 
     213             :     OGRFeature *GetFeature2002(int);
     214             :     void AddFieldDefns2002();
     215             : 
     216             :     const TigerRecordInfo *psRT1Info;
     217             :     const TigerRecordInfo *psRT2Info;
     218             :     const TigerRecordInfo *psRT3Info;
     219             : 
     220             :     CPL_DISALLOW_COPY_ASSIGN(TigerCompleteChain)
     221             : 
     222             :   public:
     223             :     TigerCompleteChain(OGRTigerDataSource *, const char *);
     224             :     ~TigerCompleteChain() override;
     225             : 
     226             :     bool SetModule(const char *) override;
     227             : 
     228             :     OGRFeature *GetFeature(int) override;
     229             : };
     230             : 
     231             : /************************************************************************/
     232             : /*                    TigerAltName (Type 4 records)                     */
     233             : /************************************************************************/
     234             : 
     235             : class TigerAltName final : public TigerFileBase
     236             : {
     237             :   public:
     238             :     TigerAltName(OGRTigerDataSource *, const char *);
     239             : 
     240             :     OGRFeature *GetFeature(int) override;
     241             : };
     242             : 
     243             : /************************************************************************/
     244             : /*                   TigerFeatureIds (Type 5 records)                   */
     245             : /************************************************************************/
     246             : 
     247           0 : class TigerFeatureIds final : public TigerFileBase
     248             : {
     249             :   public:
     250             :     TigerFeatureIds(OGRTigerDataSource *, const char *);
     251             : 
     252             :     ~TigerFeatureIds() override;
     253             : };
     254             : 
     255             : /************************************************************************/
     256             : /*                    TigerZipCodes (Type 6 records)                    */
     257             : /************************************************************************/
     258             : 
     259           0 : class TigerZipCodes final : public TigerFileBase
     260             : {
     261             :   public:
     262             :     TigerZipCodes(OGRTigerDataSource *, const char *);
     263             : 
     264             :     ~TigerZipCodes() override;
     265             : };
     266             : 
     267             : /************************************************************************/
     268             : /*                    TigerPoint                                        */
     269             : /* This is an abstract base class for TIGER layers with point geometry. */
     270             : /* Since much of the implementation of these layers is similar, I've    */
     271             : /* put it into this base class to avoid duplication in the actual       */
     272             : /* layer classes.  mbp Sat Jan  4 16:41:19 2003.                        */
     273             : /************************************************************************/
     274             : 
     275             : class TigerPoint CPL_NON_FINAL : public TigerFileBase
     276             : {
     277             :   protected:
     278             :     explicit TigerPoint(const TigerRecordInfo *psRTInfoIn = nullptr,
     279             :                         const char *m_pszFileCodeIn = nullptr);
     280             : 
     281             :   public:
     282             :     OGRFeature *GetFeature(int nFID) override;
     283             : 
     284             :     OGRFeature *GetFeature(int nRecordId, int nX0, int nX1, int nY0, int nY1);
     285             : };
     286             : 
     287             : /************************************************************************/
     288             : /*                   TigerLandmarks (Type 7 records)                    */
     289             : /************************************************************************/
     290             : 
     291             : class TigerLandmarks final : public TigerPoint
     292             : {
     293             :   public:
     294             :     TigerLandmarks(OGRTigerDataSource *, const char *);
     295             : 
     296             :     OGRFeature *GetFeature(int) override;
     297             : };
     298             : 
     299             : /************************************************************************/
     300             : /*                 TigerAreaLandmarks (Type 8 records)                  */
     301             : /************************************************************************/
     302             : 
     303           0 : class TigerAreaLandmarks final : public TigerFileBase
     304             : {
     305             :   public:
     306             :     TigerAreaLandmarks(OGRTigerDataSource *, const char *);
     307             : 
     308             :     ~TigerAreaLandmarks() override;
     309             : };
     310             : 
     311             : /************************************************************************/
     312             : /*                  TigerKeyFeatures (Type 9 records)                   */
     313             : /************************************************************************/
     314             : 
     315           0 : class TigerKeyFeatures final : public TigerFileBase
     316             : {
     317             :   public:
     318             :     TigerKeyFeatures(OGRTigerDataSource *, const char *);
     319             : 
     320             :     ~TigerKeyFeatures() override;
     321             : };
     322             : 
     323             : /************************************************************************/
     324             : /*                   TigerPolygon (Type A&S records)                    */
     325             : /************************************************************************/
     326             : 
     327             : class TigerPolygon final : public TigerFileBase
     328             : {
     329             :   private:
     330             :     const TigerRecordInfo *psRTAInfo;
     331             :     const TigerRecordInfo *psRTSInfo;
     332             : 
     333             :     VSILFILE *fpRTS;
     334             :     bool bUsingRTS;
     335             :     int nRTSRecLen;
     336             : 
     337             :     CPL_DISALLOW_COPY_ASSIGN(TigerPolygon)
     338             : 
     339             :   public:
     340             :     TigerPolygon(OGRTigerDataSource *, const char *);
     341             :     ~TigerPolygon() override;
     342             : 
     343             :     bool SetModule(const char *) override;
     344             : 
     345             :     OGRFeature *GetFeature(int) override;
     346             : };
     347             : 
     348             : /************************************************************************/
     349             : /*               TigerPolygonCorrections (Type B records)               */
     350             : /************************************************************************/
     351             : 
     352           0 : class TigerPolygonCorrections final : public TigerFileBase
     353             : {
     354             :   public:
     355             :     TigerPolygonCorrections(OGRTigerDataSource *, const char *);
     356             : 
     357             :     ~TigerPolygonCorrections() override;
     358             : };
     359             : 
     360             : /************************************************************************/
     361             : /*                  TigerEntityNames (Type C records)                   */
     362             : /************************************************************************/
     363             : 
     364           0 : class TigerEntityNames final : public TigerFileBase
     365             : {
     366             :   public:
     367             :     TigerEntityNames(OGRTigerDataSource *, const char *);
     368             : 
     369             :     ~TigerEntityNames() override;
     370             : };
     371             : 
     372             : /************************************************************************/
     373             : /*                TigerPolygonEconomic (Type E records)                 */
     374             : /************************************************************************/
     375             : 
     376           0 : class TigerPolygonEconomic final : public TigerFileBase
     377             : {
     378             :   public:
     379             :     TigerPolygonEconomic(OGRTigerDataSource *, const char *);
     380             : 
     381             :     ~TigerPolygonEconomic() override;
     382             : };
     383             : 
     384             : /************************************************************************/
     385             : /*                   TigerIDHistory (Type H records)                    */
     386             : /************************************************************************/
     387             : 
     388           0 : class TigerIDHistory final : public TigerFileBase
     389             : {
     390             :   public:
     391             :     TigerIDHistory(OGRTigerDataSource *, const char *);
     392             : 
     393             :     ~TigerIDHistory() override;
     394             : };
     395             : 
     396             : /************************************************************************/
     397             : /*                 TigerPolyChainLink (Type I records)                  */
     398             : /************************************************************************/
     399             : 
     400           0 : class TigerPolyChainLink final : public TigerFileBase
     401             : {
     402             :   public:
     403             :     TigerPolyChainLink(OGRTigerDataSource *, const char *);
     404             : 
     405             :     ~TigerPolyChainLink() override;
     406             : };
     407             : 
     408             : /************************************************************************/
     409             : /*                TigerSpatialMetadata (Type M records)                 */
     410             : /************************************************************************/
     411             : 
     412           0 : class TigerSpatialMetadata final : public TigerFileBase
     413             : {
     414             :   public:
     415             :     TigerSpatialMetadata(OGRTigerDataSource *, const char *);
     416             : 
     417             :     ~TigerSpatialMetadata() override;
     418             : };
     419             : 
     420             : /************************************************************************/
     421             : /*                      TigerPIP (Type P records)                       */
     422             : /************************************************************************/
     423             : 
     424             : class TigerPIP final : public TigerPoint
     425             : {
     426             :   public:
     427             :     TigerPIP(OGRTigerDataSource *, const char *);
     428             : 
     429             :     OGRFeature *GetFeature(int) override;
     430             : };
     431             : 
     432             : /************************************************************************/
     433             : /*                   TigerTLIDRange (Type R records)                    */
     434             : /************************************************************************/
     435             : 
     436           0 : class TigerTLIDRange final : public TigerFileBase
     437             : {
     438             :   public:
     439             :     TigerTLIDRange(OGRTigerDataSource *, const char *);
     440             : 
     441             :     ~TigerTLIDRange() override;
     442             : };
     443             : 
     444             : /************************************************************************/
     445             : /*                   TigerZeroCellID (Type T records)                   */
     446             : /************************************************************************/
     447             : 
     448           0 : class TigerZeroCellID final : public TigerFileBase
     449             : {
     450             :   public:
     451             :     TigerZeroCellID(OGRTigerDataSource *, const char *);
     452             : 
     453             :     ~TigerZeroCellID() override;
     454             : };
     455             : 
     456             : /************************************************************************/
     457             : /*                   TigerOverUnder (Type U records)                    */
     458             : /************************************************************************/
     459             : 
     460             : class TigerOverUnder final : public TigerPoint
     461             : {
     462             :   public:
     463             :     TigerOverUnder(OGRTigerDataSource *, const char *);
     464             : 
     465             :     OGRFeature *GetFeature(int) override;
     466             : };
     467             : 
     468             : /************************************************************************/
     469             : /*                    TigerZipPlus4 (Type Z records)                    */
     470             : /************************************************************************/
     471             : 
     472           0 : class TigerZipPlus4 final : public TigerFileBase
     473             : {
     474             :   public:
     475             :     TigerZipPlus4(OGRTigerDataSource *, const char *);
     476             : 
     477             :     ~TigerZipPlus4() override;
     478             : };
     479             : 
     480             : /************************************************************************/
     481             : /*                            OGRTigerLayer                             */
     482             : /************************************************************************/
     483             : 
     484             : class OGRTigerLayer final : public OGRLayer
     485             : {
     486             :     TigerFileBase *poReader;
     487             : 
     488             :     OGRTigerDataSource *poDS;
     489             : 
     490             :     int nFeatureCount;
     491             :     int *panModuleFCount;
     492             :     int *panModuleOffset;
     493             : 
     494             :     int iLastFeatureId;
     495             :     int iLastModule;
     496             : 
     497             :     CPL_DISALLOW_COPY_ASSIGN(OGRTigerLayer)
     498             : 
     499             :   public:
     500             :     OGRTigerLayer(OGRTigerDataSource *poDS, TigerFileBase *);
     501             :     ~OGRTigerLayer() override;
     502             : 
     503             :     void ResetReading() override;
     504             :     OGRFeature *GetNextFeature() override;
     505             :     OGRFeature *GetFeature(GIntBig nFeatureId) override;
     506             : 
     507             :     OGRFeatureDefn *GetLayerDefn() const override;
     508             : 
     509             :     GIntBig GetFeatureCount(int) override;
     510             : 
     511             :     int TestCapability(const char *) const override;
     512             : };
     513             : 
     514             : /************************************************************************/
     515             : /*                          OGRTigerDataSource                          */
     516             : /************************************************************************/
     517             : 
     518             : class OGRTigerDataSource final : public GDALDataset
     519             : {
     520             :     int nLayers;
     521             :     OGRTigerLayer **papoLayers;
     522             : 
     523             :     OGRSpatialReference *poSpatialRef;
     524             : 
     525             :     char **papszOptions;
     526             : 
     527             :     char *pszPath;
     528             : 
     529             :     int nModules;
     530             :     char **papszModules;
     531             : 
     532             :     int nVersionCode;
     533             :     TigerVersion nVersion;
     534             : 
     535             :     TigerVersion TigerCheckVersion(TigerVersion, const char *);
     536             : 
     537             :     CPL_DISALLOW_COPY_ASSIGN(OGRTigerDataSource)
     538             : 
     539             :   public:
     540             :     OGRTigerDataSource();
     541             :     ~OGRTigerDataSource() override;
     542             : 
     543           0 :     TigerVersion GetVersion() const
     544             :     {
     545           0 :         return nVersion;
     546             :     }
     547             : 
     548             :     int GetVersionCode() const
     549             :     {
     550             :         return nVersionCode;
     551             :     }
     552             : 
     553             :     const char *GetOption(const char *);
     554             : 
     555             :     int Open(const char *pszName, int bTestOpen = FALSE,
     556             :              char **papszFileList = nullptr);
     557             : 
     558             :     int GetLayerCount() const override;
     559             :     OGRLayer *GetLayer(int) const override;
     560             :     OGRLayer *GetLayer(const char *pszLayerName);
     561             : 
     562             :     void AddLayer(OGRTigerLayer *);
     563             : 
     564           0 :     OGRSpatialReference *DSGetSpatialRef()
     565             :     {
     566           0 :         return poSpatialRef;
     567             :     }
     568             : 
     569          78 :     const char *GetDirPath()
     570             :     {
     571          78 :         return pszPath;
     572             :     }
     573             : 
     574             :     char *BuildFilename(const char *pszModule, const char *pszExtension);
     575             : 
     576           0 :     int GetModuleCount() const
     577             :     {
     578           0 :         return nModules;
     579             :     }
     580             : 
     581             :     const char *GetModule(int);
     582             :     bool CheckModule(const char *pszModule);
     583             :     void AddModule(const char *pszModule);
     584             : };
     585             : 
     586             : #endif /* ndef OGR_TIGER_H_INCLUDED */

Generated by: LCOV version 1.14