Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: EDIGEO Translator
4 : * Purpose: Definition of classes for OGR .edigeo driver.
5 : * Author: Even Rouault, even dot rouault at spatialys.com
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2011, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * SPDX-License-Identifier: MIT
11 : ****************************************************************************/
12 :
13 : #ifndef OGR_EDIGEO_H_INCLUDED
14 : #define OGR_EDIGEO_H_INCLUDED
15 :
16 : #include "ogrsf_frmts.h"
17 : #include <vector>
18 : #include <map>
19 : #include <mutex>
20 : #include <set>
21 :
22 : /************************************************************************/
23 : /* OGREDIGEOLayer */
24 : /************************************************************************/
25 :
26 : class OGREDIGEODataSource;
27 :
28 : class OGREDIGEOLayer final : public OGRLayer,
29 : public OGRGetNextFeatureThroughRaw<OGREDIGEOLayer>
30 : {
31 : OGREDIGEODataSource *poDS;
32 :
33 : OGRFeatureDefn *poFeatureDefn;
34 : OGRSpatialReference *poSRS;
35 :
36 : int nNextFID;
37 :
38 : OGRFeature *GetNextRawFeature();
39 :
40 : std::vector<OGRFeature *> aosFeatures;
41 :
42 : /* Map attribute RID ('TEX2_id') to its index in the OGRFeatureDefn */
43 : std::map<CPLString, int> mapAttributeToIndex;
44 :
45 : public:
46 : OGREDIGEOLayer(OGREDIGEODataSource *poDS, const char *pszName,
47 : OGRwkbGeometryType eType, OGRSpatialReference *poSRS);
48 : ~OGREDIGEOLayer() override;
49 :
50 : void ResetReading() override;
51 0 : DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGREDIGEOLayer)
52 : OGRFeature *GetFeature(GIntBig nFID) override;
53 : GIntBig GetFeatureCount(int bForce) override;
54 :
55 0 : OGRFeatureDefn *GetLayerDefn() const override
56 : {
57 0 : return poFeatureDefn;
58 : }
59 :
60 : int TestCapability(const char *) const override;
61 :
62 : void AddFeature(OGRFeature *poFeature);
63 :
64 : int GetAttributeIndex(const CPLString &osRID);
65 : void AddFieldDefn(const CPLString &osName, OGRFieldType eType,
66 : const CPLString &osRID);
67 : };
68 :
69 : /************************************************************************/
70 : /* OGREDIGEODataSource */
71 : /************************************************************************/
72 :
73 : typedef std::pair<int, int> intintType;
74 : typedef std::pair<double, double> xyPairType;
75 : typedef std::vector<xyPairType> xyPairListType;
76 : typedef std::pair<CPLString, CPLString> strstrType;
77 : typedef std::vector<CPLString> strListType;
78 :
79 : /* From the .DIC file */
80 : class OGREDIGEOAttributeDef
81 : {
82 : public:
83 0 : OGREDIGEOAttributeDef()
84 0 : {
85 0 : }
86 :
87 : CPLString osLAB; /* e.g. TEX2 */
88 : CPLString osTYP; /* e.g. T */
89 : };
90 :
91 : /* From the .SCD file */
92 : class OGREDIGEOObjectDescriptor
93 : {
94 : public:
95 0 : OGREDIGEOObjectDescriptor()
96 0 : {
97 0 : }
98 :
99 : CPLString osRID; /* e.g. BATIMENT_id */
100 : CPLString osNameRID; /* e.g. ID_N_OBJ_E_2_1_0 */
101 : CPLString osKND; /* e.g. ARE */
102 : strListType aosAttrRID; /* e.g. DUR_id, TEX_id */
103 : };
104 :
105 : /* From the .SCD file */
106 : class OGREDIGEOAttributeDescriptor
107 : {
108 : public:
109 0 : OGREDIGEOAttributeDescriptor() : nWidth(0)
110 : {
111 0 : }
112 :
113 : CPLString osRID; /* e.g. TEX2_id */
114 : CPLString osNameRID; /* e.g. ID_N_ATT_TEX2 */
115 : int nWidth; /* e.g. 80 */
116 : };
117 :
118 : /* From the .VEC files */
119 : class OGREDIGEOFEADesc
120 : {
121 : public:
122 0 : OGREDIGEOFEADesc()
123 0 : {
124 0 : }
125 :
126 : std::vector<strstrType>
127 : aosAttIdVal; /* e.g. (TEX2_id,BECHEREL),(IDU_id,022) */
128 : CPLString osSCP; /* e.g. COMMUNE_id */
129 : CPLString osQUP_RID; /* e.g. Actualite_Objet_X */
130 : };
131 :
132 : class OGREDIGEODataSource final : public GDALDataset
133 : {
134 : friend class OGREDIGEOLayer;
135 :
136 : mutable VSILFILE *fpTHF;
137 :
138 : mutable OGRLayer **papoLayers;
139 : mutable int nLayers;
140 :
141 : VSILFILE *OpenFile(const char *pszType, const CPLString &osExt) const;
142 :
143 : // TODO: Translate comments to English.
144 : mutable CPLString osLON; /* Nom du lot */
145 : mutable CPLString osGNN; /* Nom du sous-ensemble de données générales */
146 : mutable CPLString
147 : osGON; /* Nom du sous-ensemble de la référence de coordonnées */
148 : mutable CPLString osQAN; /* Nom du sous-ensemble de qualité */
149 : mutable CPLString
150 : osDIN; /* Nom du sous-ensemble de définition de la nomenclature */
151 : mutable CPLString osSCN; /* Nom du sous-ensemble de définition du SCD */
152 : mutable strListType
153 : aosGDN; /* Nom du sous-ensemble de données géographiques */
154 : int ReadTHF(VSILFILE *fp) const;
155 :
156 : mutable CPLString osREL;
157 : mutable OGRSpatialReference *poSRS;
158 : int ReadGEO() const;
159 :
160 : /* Map from ID_N_OBJ_E_2_1_0 to OBJ_E_2_1_0 */
161 : mutable std::map<CPLString, CPLString> mapObjects;
162 :
163 : /* Map from ID_N_ATT_TEX2 to (osLAB=TEX2, osTYP=T) */
164 : mutable std::map<CPLString, OGREDIGEOAttributeDef> mapAttributes;
165 : int ReadDIC() const;
166 :
167 : mutable std::vector<OGREDIGEOObjectDescriptor> aoObjList;
168 : /* Map from TEX2_id to (osNameRID=ID_N_ATT_TEX2, nWidth=80) */
169 : mutable std::map<CPLString, OGREDIGEOAttributeDescriptor> mapAttributesSCD;
170 : int ReadSCD() const;
171 :
172 : mutable int bExtentValid;
173 : mutable double dfMinX;
174 : mutable double dfMinY;
175 : mutable double dfMaxX;
176 : mutable double dfMaxY;
177 : int ReadGEN() const;
178 :
179 : /* Map from Actualite_Objet_X to (creationData, updateData) */
180 : mutable std::map<CPLString, intintType> mapQAL;
181 : int ReadQAL() const;
182 :
183 : mutable std::map<CPLString, OGREDIGEOLayer *> mapLayer;
184 :
185 : int
186 : CreateLayerFromObjectDesc(const OGREDIGEOObjectDescriptor &objDesc) const;
187 :
188 : mutable std::map<CPLString, xyPairType> mapPNO; /* Map Noeud_X to (x,y) */
189 : mutable std::map<CPLString, xyPairListType>
190 : mapPAR; /* Map Arc_X to ((x1,y1),...(xn,yn)) */
191 : mutable std::map<CPLString, OGREDIGEOFEADesc>
192 : mapFEA; /* Map Object_X to FEADesc */
193 : mutable std::map<CPLString, strListType>
194 : mapPFE_PAR; /* Map Face_X to (Arc_X1,..Arc_Xn) */
195 : mutable std::vector<std::pair<CPLString, strListType>>
196 : listFEA_PFE; /* List of (Object_X,(Face_Y1,..Face_Yn)) */
197 : mutable std::vector<std::pair<CPLString, strListType>>
198 : listFEA_PAR; /* List of (Object_X,(Arc_Y1,..Arc_Yn))) */
199 : mutable std::vector<strstrType>
200 : listFEA_PNO; /* List of (Object_X,Noeud_Y) */
201 : mutable std::map<CPLString, CPLString>
202 : mapFEA_FEA; /* Map Attribut_TEX{X}_id_Objet_{Y} to Objet_Y */
203 :
204 : mutable int bRecodeToUTF8;
205 : mutable int bHasUTF8ContentOnly;
206 :
207 : int ReadVEC(const char *pszVECName) const;
208 :
209 : OGRFeature *CreateFeature(const CPLString &osFEA) const;
210 : int BuildPoints() const;
211 : int BuildLineStrings() const;
212 : int BuildPolygon(const CPLString &osFEA, const strListType &aosPFE) const;
213 : int BuildPolygons() const;
214 :
215 : mutable int iATR, iDI3, iDI4, iHEI, iFON;
216 : mutable int iATR_VAL, iANGLE, iSIZE, iOBJ_LNK, iOBJ_LNK_LAYER;
217 : mutable double dfSizeFactor;
218 : mutable int bIncludeFontFamily;
219 : int SetStyle(const CPLString &osFEA, OGRFeature *poFeature) const;
220 :
221 : mutable std::set<CPLString> setLayersWithLabels;
222 : void CreateLabelLayers() const;
223 :
224 : mutable bool bHasReadEDIGEO = false;
225 : mutable std::recursive_mutex m_oMutex{};
226 : void ReadEDIGEO() const;
227 :
228 : public:
229 : OGREDIGEODataSource();
230 : ~OGREDIGEODataSource() override;
231 :
232 : int Open(const char *pszFilename);
233 :
234 : int GetLayerCount() const override;
235 : const OGRLayer *GetLayer(int) const override;
236 :
237 0 : int HasUTF8ContentOnly()
238 : {
239 0 : return bHasUTF8ContentOnly;
240 : }
241 : };
242 :
243 : #endif /* ndef OGR_EDIGEO_H_INCLUDED */
|