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: 2024-11-21 22:18:42 Functions: 1 9 11.1 %

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

Generated by: LCOV version 1.14