LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sxf - ogr_sxf.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 8 8 100.0 %
Date: 2024-11-21 22:18:42 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  SXF Translator
       5             :  * Purpose:  Include file defining classes for OGR SXF driver, datasource and
       6             :  *layers. Author:   Ben Ahmed Daho Ali, bidandou(at)yahoo(dot)fr Dmitry
       7             :  *Baryshnikov, polimax@mail.ru Alexandr Lisovenko, alexander.lisovenko@gmail.com
       8             :  *
       9             :  ******************************************************************************
      10             :  * Copyright (c) 2011, Ben Ahmed Daho Ali
      11             :  * Copyright (c) 2013, NextGIS
      12             :  *
      13             :  * SPDX-License-Identifier: MIT
      14             :  ****************************************************************************/
      15             : 
      16             : #ifndef OGR_SXF_H_INCLUDED
      17             : #define OGR_SXF_H_INCLUDED
      18             : 
      19             : #include <set>
      20             : #include <vector>
      21             : #include <map>
      22             : 
      23             : #include "ogrsf_frmts.h"
      24             : #include "org_sxf_defs.h"
      25             : 
      26             : #define CHECK_BIT(var, pos) (((var) & (1 << (pos))) != 0)
      27             : constexpr double TO_DEGREES = 180.0 / M_PI;
      28             : constexpr double TO_RADIANS = M_PI / 180.0;
      29             : 
      30             : /************************************************************************/
      31             : /*                         OGRSXFLayer                                */
      32             : /************************************************************************/
      33             : class OGRSXFLayer final : public OGRLayer
      34             : {
      35             :   protected:
      36             :     OGRFeatureDefn *poFeatureDefn;
      37             :     VSILFILE *fpSXF;
      38             :     GByte nLayerID;
      39             :     std::map<unsigned, CPLString> mnClassificators;
      40             :     std::map<long, vsi_l_offset> mnRecordDesc;
      41             :     std::map<long, vsi_l_offset>::const_iterator oNextIt;
      42             :     SXFMapDescription stSXFMapDescription;
      43             :     std::set<GUInt16> snAttributeCodes;
      44             :     int m_nSXFFormatVer;
      45             :     CPLString sFIDColumn_;
      46             :     CPLMutex **m_hIOMutex;
      47             :     double m_dfCoeff;
      48             :     virtual OGRFeature *GetNextRawFeature(long nFID);
      49             : 
      50             :     GUInt32 TranslateXYH(const SXFRecordDescription &certifInfo,
      51             :                          const char *psBuff, GUInt32 nBufLen, double *dfX,
      52             :                          double *dfY, double *dfH = nullptr);
      53             : 
      54             :     OGRFeature *TranslatePoint(const SXFRecordDescription &certifInfo,
      55             :                                const char *psRecordBuf, GUInt32 nBufLen);
      56             :     OGRFeature *TranslateText(const SXFRecordDescription &certifInfo,
      57             :                               const char *psBuff, GUInt32 nBufLen);
      58             :     OGRFeature *TranslatePolygon(const SXFRecordDescription &certifInfo,
      59             :                                  const char *psBuff, GUInt32 nBufLen);
      60             :     OGRFeature *TranslateLine(const SXFRecordDescription &certifInfo,
      61             :                               const char *psBuff, GUInt32 nBufLen);
      62             :     OGRFeature *TranslateVetorAngle(const SXFRecordDescription &certifInfo,
      63             :                                     const char *psBuff, GUInt32 nBufLen);
      64             : 
      65             :   public:
      66             :     OGRSXFLayer(VSILFILE *fp, CPLMutex **hIOMutex, GByte nID,
      67             :                 const char *pszLayerName, int nVer,
      68             :                 const SXFMapDescription &sxfMapDesc);
      69             :     virtual ~OGRSXFLayer();
      70             : 
      71             :     virtual void ResetReading() override;
      72             :     virtual OGRFeature *GetNextFeature() override;
      73             :     virtual OGRErr SetNextByIndex(GIntBig nIndex) override;
      74             :     virtual OGRFeature *GetFeature(GIntBig nFID) override;
      75             : 
      76        8220 :     virtual OGRFeatureDefn *GetLayerDefn() override
      77             :     {
      78        8220 :         return poFeatureDefn;
      79             :     }
      80             : 
      81             :     virtual int TestCapability(const char *) override;
      82             : 
      83             :     virtual GIntBig GetFeatureCount(int bForce = TRUE) override;
      84             :     virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
      85             : 
      86          36 :     virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
      87             :                              int bForce) override
      88             :     {
      89          36 :         return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
      90             :     }
      91             : 
      92             :     virtual OGRSpatialReference *GetSpatialRef() override;
      93             :     virtual const char *GetFIDColumn() override;
      94             : 
      95       18820 :     virtual GByte GetId() const
      96             :     {
      97       18820 :         return nLayerID;
      98             :     }
      99             : 
     100             :     virtual void AddClassifyCode(unsigned nClassCode,
     101             :                                  const char *szName = nullptr);
     102             :     virtual bool AddRecord(long nFID, unsigned nClassCode, vsi_l_offset nOffset,
     103             :                            bool bHasSemantic, size_t nSemanticsSize);
     104             : 
     105             :   private:
     106             :     static int CanRecode(const char *pszEncoding);
     107             : };
     108             : 
     109             : /************************************************************************/
     110             : /*                           OGRSXFDataSource                           */
     111             : /************************************************************************/
     112             : 
     113             : class OGRSXFDataSource final : public GDALDataset
     114             : {
     115             :     SXFPassport oSXFPassport;
     116             : 
     117             :     std::vector<std::unique_ptr<OGRSXFLayer>> m_apoLayers{};
     118             : 
     119             :     VSILFILE *fpSXF = nullptr;
     120             :     CPLMutex *hIOMutex = nullptr;
     121             :     void FillLayers();
     122             :     void CreateLayers();
     123             :     void CreateLayers(VSILFILE *fpRSC, const char *const *papszOpenOpts);
     124             :     static OGRErr ReadSXFInformationFlags(VSILFILE *fpSXF,
     125             :                                           SXFPassport &passport);
     126             :     OGRErr ReadSXFDescription(VSILFILE *fpSXF, SXFPassport &passport);
     127             :     static void SetVertCS(const long iVCS, SXFPassport &passport,
     128             :                           const char *const *papszOpenOpts);
     129             :     static OGRErr ReadSXFMapDescription(VSILFILE *fpSXF, SXFPassport &passport,
     130             :                                         const char *const *papszOpenOpts);
     131             :     OGRSXFLayer *GetLayerById(GByte);
     132             : 
     133             :   public:
     134             :     OGRSXFDataSource();
     135             :     virtual ~OGRSXFDataSource();
     136             : 
     137             :     int Open(const char *pszFilename, bool bUpdate,
     138             :              const char *const *papszOpenOpts = nullptr);
     139             : 
     140        1878 :     virtual int GetLayerCount() override
     141             :     {
     142        1878 :         return static_cast<int>(m_apoLayers.size());
     143             :     }
     144             : 
     145             :     virtual OGRLayer *GetLayer(int) override;
     146             : 
     147             :     virtual int TestCapability(const char *) override;
     148             :     void CloseFile();
     149             : };
     150             : 
     151             : #endif

Generated by: LCOV version 1.14