Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: GML Reader
5 : * Purpose: Declarations for OGR wrapper classes for GML, and GML<->OGR
6 : * translation of geometry.
7 : * Author: Frank Warmerdam, warmerdam@pobox.com
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2002, Frank Warmerdam
11 : * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
12 : *
13 : * Permission is hereby granted, free of charge, to any person obtaining a
14 : * copy of this software and associated documentation files (the "Software"),
15 : * to deal in the Software without restriction, including without limitation
16 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 : * and/or sell copies of the Software, and to permit persons to whom the
18 : * Software is furnished to do so, subject to the following conditions:
19 : *
20 : * The above copyright notice and this permission notice shall be included
21 : * in all copies or substantial portions of the Software.
22 : *
23 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 : * DEALINGS IN THE SOFTWARE.
30 : ****************************************************************************/
31 :
32 : #ifndef OGR_GML_H_INCLUDED
33 : #define OGR_GML_H_INCLUDED
34 :
35 : #include "ogrsf_frmts.h"
36 : #include "gmlreader.h"
37 : #include "gmlutils.h"
38 :
39 : #include <memory>
40 : #include <vector>
41 :
42 : class OGRGMLDataSource;
43 :
44 : typedef enum
45 : {
46 : STANDARD,
47 : SEQUENTIAL_LAYERS,
48 : INTERLEAVED_LAYERS
49 : } ReadMode;
50 :
51 : /************************************************************************/
52 : /* OGRGMLLayer */
53 : /************************************************************************/
54 :
55 : class OGRGMLLayer final : public OGRLayer
56 : {
57 : OGRFeatureDefn *poFeatureDefn;
58 :
59 : GIntBig iNextGMLId;
60 : bool bInvalidFIDFound;
61 : char *pszFIDPrefix;
62 :
63 : bool bWriter;
64 : bool bSameSRS;
65 :
66 : OGRGMLDataSource *poDS;
67 :
68 : GMLFeatureClass *poFClass;
69 :
70 : void *hCacheSRS;
71 :
72 : bool bUseOldFIDFormat;
73 :
74 : bool bFaceHoleNegative;
75 :
76 : public:
77 : OGRGMLLayer(const char *pszName, bool bWriter, OGRGMLDataSource *poDS);
78 :
79 : virtual ~OGRGMLLayer();
80 :
81 : GDALDataset *GetDataset() override;
82 :
83 : void ResetReading() override;
84 : OGRFeature *GetNextFeature() override;
85 :
86 : GIntBig GetFeatureCount(int bForce = TRUE) override;
87 : OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
88 :
89 11 : virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
90 : int bForce) override
91 : {
92 11 : return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
93 : }
94 :
95 : OGRErr ICreateFeature(OGRFeature *poFeature) override;
96 :
97 6650 : OGRFeatureDefn *GetLayerDefn() override
98 : {
99 6650 : return poFeatureDefn;
100 : }
101 :
102 : virtual OGRErr CreateField(const OGRFieldDefn *poField,
103 : int bApproxOK = TRUE) override;
104 : virtual OGRErr CreateGeomField(const OGRGeomFieldDefn *poField,
105 : int bApproxOK = TRUE) override;
106 :
107 : int TestCapability(const char *) override;
108 : };
109 :
110 : /************************************************************************/
111 : /* OGRGMLDataSource */
112 : /************************************************************************/
113 :
114 : class OGRGMLDataSource final : public OGRDataSource
115 : {
116 : OGRLayer **papoLayers;
117 : int nLayers;
118 :
119 : char *pszName;
120 :
121 : OGRGMLLayer *TranslateGMLSchema(GMLFeatureClass *);
122 :
123 : char **papszCreateOptions;
124 :
125 : // output related parameters
126 : VSILFILE *fpOutput;
127 : bool bFpOutputIsNonSeekable;
128 : bool bFpOutputSingleFile;
129 : OGREnvelope3D sBoundingRect;
130 : bool bBBOX3D;
131 : int nBoundedByLocation;
132 :
133 : int nSchemaInsertLocation;
134 : bool bIsOutputGML3;
135 : bool bIsOutputGML3Deegree; /* if TRUE, then bIsOutputGML3 is also TRUE */
136 : bool bIsOutputGML32; /* if TRUE, then bIsOutputGML3 is also TRUE */
137 : OGRGMLSRSNameFormat eSRSNameFormat;
138 : bool bWriteSpaceIndentation;
139 :
140 : OGRSpatialReference *poWriteGlobalSRS;
141 : bool bWriteGlobalSRS;
142 :
143 : // input related parameters.
144 : CPLString osFilename;
145 : CPLString osXSDFilename;
146 :
147 : IGMLReader *poReader;
148 : bool bOutIsTempFile;
149 :
150 : void InsertHeader();
151 :
152 : bool bExposeGMLId;
153 : bool bExposeFid;
154 : bool bIsWFS;
155 :
156 : bool bUseGlobalSRSName;
157 :
158 : bool m_bInvertAxisOrderIfLatLong;
159 : bool m_bConsiderEPSGAsURN;
160 : GMLSwapCoordinatesEnum m_eSwapCoordinates;
161 : bool m_bGetSecondaryGeometryOption;
162 :
163 : ReadMode eReadMode;
164 : GMLFeature *poStoredGMLFeature;
165 : OGRGMLLayer *poLastReadLayer;
166 :
167 : bool bEmptyAsNull;
168 :
169 : OGRSpatialReference m_oStandaloneGeomSRS{};
170 : std::unique_ptr<OGRGeometry> m_poStandaloneGeom{};
171 :
172 : std::vector<std::string> m_aosGMLExtraElements{};
173 :
174 : void FindAndParseTopElements(VSILFILE *fp);
175 : void SetExtents(double dfMinX, double dfMinY, double dfMaxX, double dfMaxY);
176 :
177 : void BuildJointClassFromXSD();
178 : void BuildJointClassFromScannedSchema();
179 :
180 : void WriteTopElements();
181 :
182 : public:
183 : OGRGMLDataSource();
184 : virtual ~OGRGMLDataSource();
185 :
186 : bool Open(GDALOpenInfo *poOpenInfo);
187 : bool Create(const char *pszFile, char **papszOptions);
188 :
189 0 : const char *GetName() override
190 : {
191 0 : return pszName;
192 : }
193 :
194 1304 : int GetLayerCount() override
195 : {
196 1304 : return nLayers;
197 : }
198 :
199 : OGRLayer *GetLayer(int) override;
200 : OGRLayer *ICreateLayer(const char *pszName,
201 : const OGRGeomFieldDefn *poGeomFieldDefn,
202 : CSLConstList papszOptions) override;
203 : int TestCapability(const char *) override;
204 :
205 253 : VSILFILE *GetOutputFP() const
206 : {
207 253 : return fpOutput;
208 : }
209 :
210 2712 : IGMLReader *GetReader() const
211 : {
212 2712 : return poReader;
213 : }
214 :
215 : void GrowExtents(OGREnvelope3D *psGeomBounds, int nCoordDimension);
216 :
217 669 : int ExposeId() const
218 : {
219 669 : return bExposeGMLId || bExposeFid;
220 : }
221 :
222 : static void PrintLine(VSILFILE *fp, const char *fmt, ...)
223 : CPL_PRINT_FUNC_FORMAT(2, 3);
224 :
225 1688 : bool IsGML3Output() const
226 : {
227 1688 : return bIsOutputGML3;
228 : }
229 :
230 132 : bool IsGML3DeegreeOutput() const
231 : {
232 132 : return bIsOutputGML3Deegree;
233 : }
234 :
235 830 : bool IsGML32Output() const
236 : {
237 830 : return bIsOutputGML32;
238 : }
239 :
240 535 : OGRGMLSRSNameFormat GetSRSNameFormat() const
241 : {
242 535 : return eSRSNameFormat;
243 : }
244 :
245 253 : bool WriteSpaceIndentation() const
246 : {
247 253 : return bWriteSpaceIndentation;
248 : }
249 :
250 : const char *GetGlobalSRSName();
251 :
252 656 : bool GetInvertAxisOrderIfLatLong() const
253 : {
254 656 : return m_bInvertAxisOrderIfLatLong;
255 : }
256 :
257 656 : bool GetConsiderEPSGAsURN() const
258 : {
259 656 : return m_bConsiderEPSGAsURN;
260 : }
261 :
262 656 : GMLSwapCoordinatesEnum GetSwapCoordinates() const
263 : {
264 656 : return m_eSwapCoordinates;
265 : }
266 :
267 656 : bool GetSecondaryGeometryOption() const
268 : {
269 656 : return m_bGetSecondaryGeometryOption;
270 : }
271 :
272 3122 : ReadMode GetReadMode() const
273 : {
274 3122 : return eReadMode;
275 : }
276 :
277 95 : void SetStoredGMLFeature(GMLFeature *poStoredGMLFeatureIn)
278 : {
279 95 : poStoredGMLFeature = poStoredGMLFeatureIn;
280 95 : }
281 :
282 1607 : GMLFeature *PeekStoredGMLFeature() const
283 : {
284 1607 : return poStoredGMLFeature;
285 : }
286 :
287 772 : OGRGMLLayer *GetLastReadLayer() const
288 : {
289 772 : return poLastReadLayer;
290 : }
291 :
292 345 : void SetLastReadLayer(OGRGMLLayer *poLayer)
293 : {
294 345 : poLastReadLayer = poLayer;
295 345 : }
296 :
297 : const char *GetAppPrefix() const;
298 : bool RemoveAppPrefix() const;
299 : bool WriteFeatureBoundedBy() const;
300 : const char *GetSRSDimensionLoc() const;
301 : bool GMLFeatureCollection() const;
302 :
303 : virtual OGRLayer *ExecuteSQL(const char *pszSQLCommand,
304 : OGRGeometry *poSpatialFilter,
305 : const char *pszDialect) override;
306 : virtual void ReleaseResultSet(OGRLayer *poResultsSet) override;
307 :
308 : static bool CheckHeader(const char *pszStr);
309 : };
310 :
311 : #endif /* OGR_GML_H_INCLUDED */
|