1 : /******************************************************************************
2 : * $Id: ogr_edigeo.h 23423 2011-11-26 18:40:30Z rouault $
3 : *
4 : * Project: EDIGEO Translator
5 : * Purpose: Definition of classes for OGR .edigeo driver.
6 : * Author: Even Rouault, even dot rouault at mines dash paris dot org
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2011, Even Rouault <even dot rouault at mines dash paris dot org>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef _OGR_EDIGEO_H_INCLUDED
31 : #define _OGR_EDIGEO_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include <vector>
35 : #include <map>
36 : #include <set>
37 :
38 : /************************************************************************/
39 : /* OGREDIGEOLayer */
40 : /************************************************************************/
41 :
42 : class OGREDIGEODataSource;
43 :
44 : class OGREDIGEOLayer : public OGRLayer
45 : {
46 : OGREDIGEODataSource* poDS;
47 :
48 : OGRFeatureDefn* poFeatureDefn;
49 : OGRSpatialReference *poSRS;
50 :
51 : int nNextFID;
52 :
53 : OGRFeature * GetNextRawFeature();
54 :
55 : std::vector<OGRFeature*> aosFeatures;
56 :
57 : /* Map attribute RID ('TEX2_id') to its index in the OGRFeatureDefn */
58 : std::map<CPLString, int> mapAttributeToIndex;
59 :
60 : public:
61 : OGREDIGEOLayer(OGREDIGEODataSource* poDS,
62 : const char* pszName, OGRwkbGeometryType eType,
63 : OGRSpatialReference* poSRS);
64 : ~OGREDIGEOLayer();
65 :
66 :
67 : virtual void ResetReading();
68 : virtual OGRFeature * GetNextFeature();
69 : virtual OGRFeature * GetFeature(long nFID);
70 : virtual int GetFeatureCount( int bForce );
71 :
72 4812 : virtual OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
73 :
74 : virtual int TestCapability( const char * );
75 :
76 34 : virtual OGRSpatialReference *GetSpatialRef() { return poSRS; }
77 :
78 : virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce);
79 :
80 :
81 : void AddFeature(OGRFeature* poFeature);
82 :
83 : int GetAttributeIndex(const CPLString& osRID);
84 : void AddFieldDefn(const CPLString& osName, OGRFieldType eType,
85 : const CPLString& osRID);
86 : };
87 :
88 : /************************************************************************/
89 : /* OGREDIGEODataSource */
90 : /************************************************************************/
91 :
92 : typedef std::pair<int, int> intintType;
93 : typedef std::pair<double, double> xyPairType;
94 : typedef std::vector< xyPairType > xyPairListType;
95 : typedef std::pair<CPLString, CPLString> strstrType;
96 : typedef std::vector<CPLString> strListType;
97 :
98 : /* From the .DIC file */
99 : class OGREDIGEOAttributeDef
100 742 : {
101 : public:
102 212 : OGREDIGEOAttributeDef() {}
103 :
104 : CPLString osLAB; /* e.g. TEX2 */
105 : CPLString osTYP; /* e.g. T */
106 : };
107 :
108 : /* From the .SCD file */
109 : class OGREDIGEOObjectDescriptor
110 256 : {
111 : public:
112 44 : OGREDIGEOObjectDescriptor() {}
113 :
114 : CPLString osRID; /* e.g. BATIMENT_id */
115 : CPLString osNameRID; /* e.g. ID_N_OBJ_E_2_1_0 */
116 : CPLString osKND; /* e.g. ARE */
117 : strListType aosAttrRID; /* e.g. DUR_id, TEX_id */
118 : };
119 :
120 : /* From the .SCD file */
121 : class OGREDIGEOAttributeDescriptor
122 742 : {
123 : public:
124 212 : OGREDIGEOAttributeDescriptor() {}
125 :
126 : CPLString osRID; /* e.g. TEX2_id */
127 : CPLString osNameRID; /* e.g. ID_N_ATT_TEX2 */
128 : int nWidth; /* e.g. 80 */
129 : };
130 :
131 : /* From the .VEC files */
132 : class OGREDIGEOFEADesc
133 10514 : {
134 : public:
135 3004 : OGREDIGEOFEADesc() {}
136 :
137 : std::vector< strstrType > aosAttIdVal; /* e.g. (TEX2_id,BECHEREL),(IDU_id,022) */
138 : CPLString osSCP; /* e.g. COMMUNE_id */
139 : CPLString osQUP_RID; /* e.g. Actualite_Objet_X */
140 : };
141 :
142 : class OGREDIGEODataSource : public OGRDataSource
143 : {
144 : friend class OGREDIGEOLayer;
145 :
146 : char* pszName;
147 : VSILFILE* fpTHF;
148 :
149 : OGRLayer** papoLayers;
150 : int nLayers;
151 :
152 : VSILFILE* OpenFile(const char *pszType,
153 : const CPLString& osExt);
154 :
155 : CPLString osLON; /* Nom du lot */
156 : CPLString osGNN; /* Nom du sous-ensemble de données générales */
157 : CPLString osGON; /* Nom du sous-ensemble de la référence de coordonnées */
158 : CPLString osQAN; /* Nom du sous-ensemble de qualité */
159 : CPLString osDIN; /* Nom du sous-ensemble de définition de la nomenclature */
160 : CPLString osSCN; /* Nom du sous-ensemble de définition du SCD */
161 : strListType aosGDN; /* Nom du sous-ensemble de données géographiques */
162 : int ReadTHF(VSILFILE* fp);
163 :
164 : CPLString osREL;
165 : OGRSpatialReference* poSRS;
166 : int ReadGEO();
167 :
168 : /* Map from ID_N_OBJ_E_2_1_0 to OBJ_E_2_1_0 */
169 : std::map<CPLString,CPLString> mapObjects;
170 :
171 : /* Map from ID_N_ATT_TEX2 to (osLAB=TEX2, osTYP=T) */
172 : std::map<CPLString,OGREDIGEOAttributeDef> mapAttributes;
173 : int ReadDIC();
174 :
175 : std::vector<OGREDIGEOObjectDescriptor> aoObjList;
176 : /* Map from TEX2_id to (osNameRID=ID_N_ATT_TEX2, nWidth=80) */
177 : std::map<CPLString,OGREDIGEOAttributeDescriptor> mapAttributesSCD;
178 : int ReadSCD();
179 :
180 : int bExtentValid;
181 : double dfMinX;
182 : double dfMinY;
183 : double dfMaxX;
184 : double dfMaxY;
185 : int ReadGEN();
186 :
187 : /* Map from Actualite_Objet_X to (creationData, updateData) */
188 : std::map<CPLString,intintType> mapQAL;
189 : int ReadQAL();
190 :
191 : std::map<CPLString, OGREDIGEOLayer*> mapLayer;
192 :
193 : int CreateLayerFromObjectDesc(const OGREDIGEOObjectDescriptor& objDesc);
194 :
195 : std::map< CPLString, xyPairType > mapPNO; /* Map Noeud_X to (x,y) */
196 : std::map< CPLString, xyPairListType > mapPAR; /* Map Arc_X to ((x1,y1),...(xn,yn)) */
197 : std::map< CPLString, OGREDIGEOFEADesc > mapFEA; /* Map Object_X to FEADesc */
198 : std::map< CPLString, strListType > mapPFE_PAR; /* Map Face_X to (Arc_X1,..Arc_Xn) */
199 : std::vector< strstrType > listFEA_PFE; /* List of (Object_X,Face_Y) */
200 : std::vector< std::pair<CPLString, strListType > > listFEA_PAR; /* List of (Object_X,(Arc_Y1,..Arc_Yn))) */
201 : std::vector< strstrType > listFEA_PNO; /* List of (Object_X,Noeud_Y) */
202 : std::map< CPLString, CPLString> mapFEA_FEA; /* Map Attribut_TEX{X}_id_Objet_{Y} to Objet_Y */
203 :
204 : int bRecodeToUTF8;
205 : int bHasUTF8ContentOnly;
206 :
207 : int ReadVEC(const char* pszVECName);
208 :
209 : OGRFeature* CreateFeature(const CPLString& osFEA);
210 : int BuildPoints();
211 : int BuildLineStrings();
212 : int BuildPolygon(const CPLString& osFEA,
213 : const CPLString& osPFE);
214 : int BuildPolygons();
215 :
216 : int iATR, iDI3, iDI4, iHEI, iFON;
217 : int iATR_VAL, iANGLE, iSIZE, iOBJ_LNK, iOBJ_LNK_LAYER;
218 : double dfSizeFactor;
219 : int bIncludeFontFamily;
220 : int SetStyle(const CPLString& osFEA,
221 : OGRFeature* poFeature);
222 :
223 : std::set< CPLString > setLayersWithLabels;
224 : void CreateLabelLayers();
225 :
226 : int bHasReadEDIGEO;
227 : void ReadEDIGEO();
228 :
229 : public:
230 : OGREDIGEODataSource();
231 : ~OGREDIGEODataSource();
232 :
233 : int Open( const char * pszFilename,
234 : int bUpdate );
235 :
236 2 : virtual const char* GetName() { return pszName; }
237 :
238 : virtual int GetLayerCount();
239 : virtual OGRLayer* GetLayer( int );
240 :
241 : virtual int TestCapability( const char * );
242 :
243 0 : int HasUTF8ContentOnly() { return bHasUTF8ContentOnly; }
244 : };
245 :
246 : /************************************************************************/
247 : /* OGREDIGEODriver */
248 : /************************************************************************/
249 :
250 : class OGREDIGEODriver : public OGRSFDriver
251 389 : {
252 : public:
253 : ~OGREDIGEODriver();
254 :
255 : virtual const char* GetName();
256 : virtual OGRDataSource* Open( const char *, int );
257 : virtual int TestCapability( const char * );
258 : };
259 :
260 :
261 : #endif /* ndef _OGR_EDIGEO_H_INCLUDED */
|