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