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 10 80.0 %
Date: 2024-04-27 17:22:41 Functions: 4 5 80.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             :  * 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_SXF_H_INCLUDED
      33             : #define OGR_SXF_H_INCLUDED
      34             : 
      35             : #include <set>
      36             : #include <vector>
      37             : #include <map>
      38             : 
      39             : #include "ogrsf_frmts.h"
      40             : #include "org_sxf_defs.h"
      41             : 
      42             : #define CHECK_BIT(var, pos) (((var) & (1 << (pos))) != 0)
      43             : constexpr double TO_DEGREES = 180.0 / M_PI;
      44             : constexpr double TO_RADIANS = M_PI / 180.0;
      45             : 
      46             : /************************************************************************/
      47             : /*                         OGRSXFLayer                                */
      48             : /************************************************************************/
      49             : class OGRSXFLayer final : public OGRLayer
      50             : {
      51             :   protected:
      52             :     OGRFeatureDefn *poFeatureDefn;
      53             :     VSILFILE *fpSXF;
      54             :     GByte nLayerID;
      55             :     std::map<unsigned, CPLString> mnClassificators;
      56             :     std::map<long, vsi_l_offset> mnRecordDesc;
      57             :     std::map<long, vsi_l_offset>::const_iterator oNextIt;
      58             :     SXFMapDescription stSXFMapDescription;
      59             :     std::set<GUInt16> snAttributeCodes;
      60             :     int m_nSXFFormatVer;
      61             :     CPLString sFIDColumn_;
      62             :     CPLMutex **m_hIOMutex;
      63             :     double m_dfCoeff;
      64             :     virtual OGRFeature *GetNextRawFeature(long nFID);
      65             : 
      66             :     GUInt32 TranslateXYH(const SXFRecordDescription &certifInfo,
      67             :                          const char *psBuff, GUInt32 nBufLen, double *dfX,
      68             :                          double *dfY, double *dfH = nullptr);
      69             : 
      70             :     OGRFeature *TranslatePoint(const SXFRecordDescription &certifInfo,
      71             :                                const char *psRecordBuf, GUInt32 nBufLen);
      72             :     OGRFeature *TranslateText(const SXFRecordDescription &certifInfo,
      73             :                               const char *psBuff, GUInt32 nBufLen);
      74             :     OGRFeature *TranslatePolygon(const SXFRecordDescription &certifInfo,
      75             :                                  const char *psBuff, GUInt32 nBufLen);
      76             :     OGRFeature *TranslateLine(const SXFRecordDescription &certifInfo,
      77             :                               const char *psBuff, GUInt32 nBufLen);
      78             :     OGRFeature *TranslateVetorAngle(const SXFRecordDescription &certifInfo,
      79             :                                     const char *psBuff, GUInt32 nBufLen);
      80             : 
      81             :   public:
      82             :     OGRSXFLayer(VSILFILE *fp, CPLMutex **hIOMutex, GByte nID,
      83             :                 const char *pszLayerName, int nVer,
      84             :                 const SXFMapDescription &sxfMapDesc);
      85             :     virtual ~OGRSXFLayer();
      86             : 
      87             :     virtual void ResetReading() override;
      88             :     virtual OGRFeature *GetNextFeature() override;
      89             :     virtual OGRErr SetNextByIndex(GIntBig nIndex) override;
      90             :     virtual OGRFeature *GetFeature(GIntBig nFID) override;
      91             : 
      92        8565 :     virtual OGRFeatureDefn *GetLayerDefn() override
      93             :     {
      94        8565 :         return poFeatureDefn;
      95             :     }
      96             : 
      97             :     virtual int TestCapability(const char *) override;
      98             : 
      99             :     virtual GIntBig GetFeatureCount(int bForce = TRUE) override;
     100             :     virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
     101             : 
     102          36 :     virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
     103             :                              int bForce) override
     104             :     {
     105          36 :         return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
     106             :     }
     107             : 
     108             :     virtual OGRSpatialReference *GetSpatialRef() override;
     109             :     virtual const char *GetFIDColumn() override;
     110             : 
     111       18820 :     virtual GByte GetId() const
     112             :     {
     113       18820 :         return nLayerID;
     114             :     }
     115             : 
     116             :     virtual void AddClassifyCode(unsigned nClassCode,
     117             :                                  const char *szName = nullptr);
     118             :     virtual bool AddRecord(long nFID, unsigned nClassCode, vsi_l_offset nOffset,
     119             :                            bool bHasSemantic, size_t nSemanticsSize);
     120             : 
     121             :   private:
     122             :     static int CanRecode(const char *pszEncoding);
     123             : };
     124             : 
     125             : /************************************************************************/
     126             : /*                        OGRSXFDataSource                       */
     127             : /************************************************************************/
     128             : 
     129             : class OGRSXFDataSource final : public OGRDataSource
     130             : {
     131             :     SXFPassport oSXFPassport;
     132             : 
     133             :     CPLString pszName{};
     134             : 
     135             :     std::vector<std::unique_ptr<OGRSXFLayer>> m_apoLayers{};
     136             : 
     137             :     VSILFILE *fpSXF = nullptr;
     138             :     CPLMutex *hIOMutex = nullptr;
     139             :     void FillLayers();
     140             :     void CreateLayers();
     141             :     void CreateLayers(VSILFILE *fpRSC, const char *const *papszOpenOpts);
     142             :     static OGRErr ReadSXFInformationFlags(VSILFILE *fpSXF,
     143             :                                           SXFPassport &passport);
     144             :     OGRErr ReadSXFDescription(VSILFILE *fpSXF, SXFPassport &passport);
     145             :     static void SetVertCS(const long iVCS, SXFPassport &passport,
     146             :                           const char *const *papszOpenOpts);
     147             :     static OGRErr ReadSXFMapDescription(VSILFILE *fpSXF, SXFPassport &passport,
     148             :                                         const char *const *papszOpenOpts);
     149             :     OGRSXFLayer *GetLayerById(GByte);
     150             : 
     151             :   public:
     152             :     OGRSXFDataSource();
     153             :     virtual ~OGRSXFDataSource();
     154             : 
     155             :     int Open(const char *pszFilename, bool bUpdate,
     156             :              const char *const *papszOpenOpts = nullptr);
     157             : 
     158           0 :     virtual const char *GetName() override
     159             :     {
     160           0 :         return pszName;
     161             :     }
     162             : 
     163        1878 :     virtual int GetLayerCount() override
     164             :     {
     165        1878 :         return static_cast<int>(m_apoLayers.size());
     166             :     }
     167             : 
     168             :     virtual OGRLayer *GetLayer(int) override;
     169             : 
     170             :     virtual int TestCapability(const char *) override;
     171             :     void CloseFile();
     172             : };
     173             : 
     174             : /************************************************************************/
     175             : /*                         OGRSXFDriver                          */
     176             : /************************************************************************/
     177             : 
     178             : class OGRSXFDriver final : public GDALDriver
     179             : {
     180             :   public:
     181             :     ~OGRSXFDriver();
     182             : 
     183             :     static GDALDataset *Open(GDALOpenInfo *);
     184             :     static int Identify(GDALOpenInfo *);
     185             :     static CPLErr DeleteDataSource(const char *pszName);
     186             : };
     187             : 
     188             : #endif

Generated by: LCOV version 1.14