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 20 10.0 %
Date: 2024-04-29 17:29:47 Functions: 1 10 10.0 %

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

Generated by: LCOV version 1.14