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 : virtual 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 : public:
65 : OGRSXFLayer(VSILFILE *fp, CPLMutex **hIOMutex, GByte nID,
66 : const char *pszLayerName, int nVer,
67 : const SXFMapDescription &sxfMapDesc);
68 : virtual ~OGRSXFLayer();
69 :
70 : virtual void ResetReading() override;
71 : virtual OGRFeature *GetNextFeature() override;
72 : virtual OGRErr SetNextByIndex(GIntBig nIndex) override;
73 : virtual OGRFeature *GetFeature(GIntBig nFID) override;
74 :
75 8166 : virtual OGRFeatureDefn *GetLayerDefn() override
76 : {
77 8166 : return poFeatureDefn;
78 : }
79 :
80 : virtual int TestCapability(const char *) override;
81 :
82 : virtual GIntBig GetFeatureCount(int bForce = TRUE) override;
83 : virtual OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent,
84 : bool bForce) override;
85 :
86 : virtual OGRSpatialReference *GetSpatialRef() override;
87 : virtual const char *GetFIDColumn() override;
88 :
89 18820 : virtual GByte GetId() const
90 : {
91 18820 : return nLayerID;
92 : }
93 :
94 : virtual void AddClassifyCode(unsigned nClassCode,
95 : const char *szName = nullptr);
96 : virtual bool AddRecord(long nFID, unsigned nClassCode, vsi_l_offset nOffset,
97 : bool bHasSemantic, size_t nSemanticsSize);
98 :
99 : private:
100 : static int CanRecode(const char *pszEncoding);
101 : };
102 :
103 : /************************************************************************/
104 : /* OGRSXFDataSource */
105 : /************************************************************************/
106 :
107 : class OGRSXFDataSource final : public GDALDataset
108 : {
109 : SXFPassport oSXFPassport;
110 :
111 : std::vector<std::unique_ptr<OGRSXFLayer>> m_apoLayers{};
112 :
113 : VSILFILE *fpSXF = nullptr;
114 : CPLMutex *hIOMutex = nullptr;
115 : void FillLayers();
116 : void CreateLayers();
117 : void CreateLayers(VSILFILE *fpRSC, const char *const *papszOpenOpts);
118 : static OGRErr ReadSXFInformationFlags(VSILFILE *fpSXF,
119 : SXFPassport &passport);
120 : OGRErr ReadSXFDescription(VSILFILE *fpSXF, SXFPassport &passport);
121 : static void SetVertCS(const long iVCS, SXFPassport &passport,
122 : const char *const *papszOpenOpts);
123 : static OGRErr ReadSXFMapDescription(VSILFILE *fpSXF, SXFPassport &passport,
124 : const char *const *papszOpenOpts);
125 : OGRSXFLayer *GetLayerById(GByte);
126 :
127 : public:
128 : OGRSXFDataSource();
129 : virtual ~OGRSXFDataSource();
130 :
131 : int Open(const char *pszFilename, bool bUpdate,
132 : const char *const *papszOpenOpts = nullptr);
133 :
134 1878 : virtual int GetLayerCount() override
135 : {
136 1878 : return static_cast<int>(m_apoLayers.size());
137 : }
138 :
139 : virtual OGRLayer *GetLayer(int) override;
140 :
141 : virtual int TestCapability(const char *) override;
142 : void CloseFile();
143 : };
144 :
145 : #endif
|