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