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: 6 6 100.0 %
Date: 2025-07-01 22:47:05 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.14