/src/gdal/ogr/ogrsf_frmts/gml/ogr_gml.h
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: GML Reader |
4 | | * Purpose: Declarations for OGR wrapper classes for GML, and GML<->OGR |
5 | | * translation of geometry. |
6 | | * Author: Frank Warmerdam, warmerdam@pobox.com |
7 | | * |
8 | | ****************************************************************************** |
9 | | * Copyright (c) 2002, Frank Warmerdam |
10 | | * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com> |
11 | | * |
12 | | * SPDX-License-Identifier: MIT |
13 | | ****************************************************************************/ |
14 | | |
15 | | #ifndef OGR_GML_H_INCLUDED |
16 | | #define OGR_GML_H_INCLUDED |
17 | | |
18 | | #include "ogrsf_frmts.h" |
19 | | #include "gmlreader.h" |
20 | | #include "gmlutils.h" |
21 | | |
22 | | #include <memory> |
23 | | #include <vector> |
24 | | |
25 | | class OGRGMLDataSource; |
26 | | |
27 | | typedef enum |
28 | | { |
29 | | STANDARD, |
30 | | SEQUENTIAL_LAYERS, |
31 | | INTERLEAVED_LAYERS |
32 | | } ReadMode; |
33 | | |
34 | | /************************************************************************/ |
35 | | /* OGRGMLLayer */ |
36 | | /************************************************************************/ |
37 | | |
38 | | class OGRGMLLayer final : public OGRLayer |
39 | | { |
40 | | OGRFeatureDefn *poFeatureDefn; |
41 | | |
42 | | GIntBig iNextGMLId; |
43 | | bool bInvalidFIDFound; |
44 | | char *pszFIDPrefix; |
45 | | |
46 | | bool bWriter; |
47 | | |
48 | | OGRGMLDataSource *poDS; |
49 | | |
50 | | GMLFeatureClass *poFClass; |
51 | | |
52 | | void *hCacheSRS; |
53 | | |
54 | | bool bUseOldFIDFormat; |
55 | | |
56 | | bool bFaceHoleNegative; |
57 | | |
58 | | CPL_DISALLOW_COPY_ASSIGN(OGRGMLLayer) |
59 | | |
60 | | public: |
61 | | OGRGMLLayer(const char *pszName, bool bWriter, OGRGMLDataSource *poDS); |
62 | | |
63 | | virtual ~OGRGMLLayer(); |
64 | | |
65 | | GDALDataset *GetDataset() override; |
66 | | |
67 | | void ResetReading() override; |
68 | | OGRFeature *GetNextFeature() override; |
69 | | |
70 | | GIntBig GetFeatureCount(int bForce = TRUE) override; |
71 | | OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent, |
72 | | bool bForce) override; |
73 | | |
74 | | OGRErr ICreateFeature(OGRFeature *poFeature) override; |
75 | | |
76 | | OGRFeatureDefn *GetLayerDefn() override |
77 | 1.05M | { |
78 | 1.05M | return poFeatureDefn; |
79 | 1.05M | } |
80 | | |
81 | | virtual OGRErr CreateField(const OGRFieldDefn *poField, |
82 | | int bApproxOK = TRUE) override; |
83 | | virtual OGRErr CreateGeomField(const OGRGeomFieldDefn *poField, |
84 | | int bApproxOK = TRUE) override; |
85 | | |
86 | | int TestCapability(const char *) override; |
87 | | }; |
88 | | |
89 | | /************************************************************************/ |
90 | | /* OGRGMLDataSource */ |
91 | | /************************************************************************/ |
92 | | |
93 | | class OGRGMLDataSource final : public GDALDataset |
94 | | { |
95 | | OGRLayer **papoLayers; |
96 | | int nLayers; |
97 | | |
98 | | OGRGMLLayer *TranslateGMLSchema(GMLFeatureClass *); |
99 | | |
100 | | char **papszCreateOptions; |
101 | | |
102 | | // output related parameters |
103 | | VSILFILE *fpOutput; |
104 | | bool bFpOutputIsNonSeekable; |
105 | | bool bFpOutputSingleFile; |
106 | | bool m_bWriteError = false; |
107 | | OGREnvelope3D sBoundingRect{}; |
108 | | bool bBBOX3D; |
109 | | int nBoundedByLocation; |
110 | | |
111 | | int nSchemaInsertLocation; |
112 | | bool bIsOutputGML3; |
113 | | bool bIsOutputGML3Deegree; /* if TRUE, then bIsOutputGML3 is also TRUE */ |
114 | | bool bIsOutputGML32; /* if TRUE, then bIsOutputGML3 is also TRUE */ |
115 | | OGRGMLSRSNameFormat eSRSNameFormat; |
116 | | bool bWriteSpaceIndentation; |
117 | | |
118 | | //! Whether all geometry fields of all layers have the same SRS (or no SRS at all) |
119 | | bool m_bWriteGlobalSRS = true; |
120 | | |
121 | | //! The global SRS (may be null), that is valid only if m_bWriteGlobalSRS == true |
122 | | std::unique_ptr<OGRSpatialReference> m_poWriteGlobalSRS{}; |
123 | | |
124 | | //! Whether at least one geometry field has been created |
125 | | bool m_bWriteGlobalSRSInit = false; |
126 | | |
127 | | // input related parameters. |
128 | | CPLString osFilename{}; |
129 | | CPLString osXSDFilename{}; |
130 | | bool m_bUnlinkXSDFilename = false; |
131 | | |
132 | | IGMLReader *poReader; |
133 | | bool bOutIsTempFile; |
134 | | |
135 | | void InsertHeader(); |
136 | | |
137 | | bool bExposeGMLId; |
138 | | bool bExposeFid; |
139 | | bool bIsWFS; |
140 | | |
141 | | bool bUseGlobalSRSName; |
142 | | |
143 | | bool m_bInvertAxisOrderIfLatLong; |
144 | | bool m_bConsiderEPSGAsURN; |
145 | | GMLSwapCoordinatesEnum m_eSwapCoordinates; |
146 | | bool m_bGetSecondaryGeometryOption; |
147 | | |
148 | | ReadMode eReadMode; |
149 | | GMLFeature *poStoredGMLFeature; |
150 | | OGRGMLLayer *poLastReadLayer; |
151 | | |
152 | | bool bEmptyAsNull; |
153 | | |
154 | | OGRSpatialReference m_oStandaloneGeomSRS{}; |
155 | | std::unique_ptr<OGRGeometry> m_poStandaloneGeom{}; |
156 | | |
157 | | std::vector<std::string> m_aosGMLExtraElements{}; |
158 | | |
159 | | void FindAndParseTopElements(VSILFILE *fp); |
160 | | void SetExtents(double dfMinX, double dfMinY, double dfMaxX, double dfMaxY); |
161 | | |
162 | | void BuildJointClassFromXSD(); |
163 | | void BuildJointClassFromScannedSchema(); |
164 | | |
165 | | void WriteTopElements(); |
166 | | |
167 | | // Analyze the OGR_SCHEMA open options and apply changes to the GML reader, return false in case of a critical error |
168 | | bool DealWithOgrSchemaOpenOption(const GDALOpenInfo *poOpenInfo); |
169 | | |
170 | | CPL_DISALLOW_COPY_ASSIGN(OGRGMLDataSource) |
171 | | |
172 | | public: |
173 | | OGRGMLDataSource(); |
174 | | virtual ~OGRGMLDataSource(); |
175 | | |
176 | | bool Open(GDALOpenInfo *poOpenInfo); |
177 | | CPLErr Close() override; |
178 | | bool Create(const char *pszFile, char **papszOptions); |
179 | | |
180 | | int GetLayerCount() override |
181 | 78.3k | { |
182 | 78.3k | return nLayers; |
183 | 78.3k | } |
184 | | |
185 | | OGRLayer *GetLayer(int) override; |
186 | | OGRLayer *ICreateLayer(const char *pszName, |
187 | | const OGRGeomFieldDefn *poGeomFieldDefn, |
188 | | CSLConstList papszOptions) override; |
189 | | int TestCapability(const char *) override; |
190 | | |
191 | | VSILFILE *GetOutputFP() const |
192 | 538k | { |
193 | 538k | return fpOutput; |
194 | 538k | } |
195 | | |
196 | | IGMLReader *GetReader() const |
197 | 236k | { |
198 | 236k | return poReader; |
199 | 236k | } |
200 | | |
201 | | void GrowExtents(OGREnvelope3D *psGeomBounds, int nCoordDimension); |
202 | | |
203 | | int ExposeId() const |
204 | 31.5k | { |
205 | 31.5k | return bExposeGMLId || bExposeFid; |
206 | 31.5k | } |
207 | | |
208 | | void PrintLine(VSILFILE *fp, const char *fmt, ...) |
209 | | CPL_PRINT_FUNC_FORMAT(3, 4); |
210 | | |
211 | | bool IsGML3Output() const |
212 | 1.09M | { |
213 | 1.09M | return bIsOutputGML3; |
214 | 1.09M | } |
215 | | |
216 | | bool IsGML3DeegreeOutput() const |
217 | 25 | { |
218 | 25 | return bIsOutputGML3Deegree; |
219 | 25 | } |
220 | | |
221 | | bool IsGML32Output() const |
222 | 1.12k | { |
223 | 1.12k | return bIsOutputGML32; |
224 | 1.12k | } |
225 | | |
226 | | /** Returns whether a writing error has occurred */ |
227 | | inline bool HasWriteError() const |
228 | 1.07M | { |
229 | 1.07M | return m_bWriteError; |
230 | 1.07M | } |
231 | | |
232 | | OGRGMLSRSNameFormat GetSRSNameFormat() const |
233 | 1.24k | { |
234 | 1.24k | return eSRSNameFormat; |
235 | 1.24k | } |
236 | | |
237 | | bool WriteSpaceIndentation() const |
238 | 538k | { |
239 | 538k | return bWriteSpaceIndentation; |
240 | 538k | } |
241 | | |
242 | | const char *GetGlobalSRSName(); |
243 | | |
244 | | bool GetInvertAxisOrderIfLatLong() const |
245 | 7.53k | { |
246 | 7.53k | return m_bInvertAxisOrderIfLatLong; |
247 | 7.53k | } |
248 | | |
249 | | bool GetConsiderEPSGAsURN() const |
250 | 7.53k | { |
251 | 7.53k | return m_bConsiderEPSGAsURN; |
252 | 7.53k | } |
253 | | |
254 | | GMLSwapCoordinatesEnum GetSwapCoordinates() const |
255 | 7.53k | { |
256 | 7.53k | return m_eSwapCoordinates; |
257 | 7.53k | } |
258 | | |
259 | | bool GetSecondaryGeometryOption() const |
260 | 7.53k | { |
261 | 7.53k | return m_bGetSecondaryGeometryOption; |
262 | 7.53k | } |
263 | | |
264 | | ReadMode GetReadMode() const |
265 | 152k | { |
266 | 152k | return eReadMode; |
267 | 152k | } |
268 | | |
269 | | void SetStoredGMLFeature(GMLFeature *poStoredGMLFeatureIn) |
270 | 8.06k | { |
271 | 8.06k | poStoredGMLFeature = poStoredGMLFeatureIn; |
272 | 8.06k | } |
273 | | |
274 | | GMLFeature *PeekStoredGMLFeature() const |
275 | 84.4k | { |
276 | 84.4k | return poStoredGMLFeature; |
277 | 84.4k | } |
278 | | |
279 | | OGRGMLLayer *GetLastReadLayer() const |
280 | 69.0k | { |
281 | 69.0k | return poLastReadLayer; |
282 | 69.0k | } |
283 | | |
284 | | void SetLastReadLayer(OGRGMLLayer *poLayer) |
285 | 37.4k | { |
286 | 37.4k | poLastReadLayer = poLayer; |
287 | 37.4k | } |
288 | | |
289 | | const char *GetAppPrefix() const; |
290 | | bool RemoveAppPrefix() const; |
291 | | bool WriteFeatureBoundedBy() const; |
292 | | const char *GetSRSDimensionLoc() const; |
293 | | bool GMLFeatureCollection() const; |
294 | | |
295 | | void DeclareNewWriteSRS(const OGRSpatialReference *poSRS); |
296 | | |
297 | | bool HasWriteGlobalSRS() const |
298 | 357 | { |
299 | 357 | return m_bWriteGlobalSRS; |
300 | 357 | } |
301 | | |
302 | | virtual OGRLayer *ExecuteSQL(const char *pszSQLCommand, |
303 | | OGRGeometry *poSpatialFilter, |
304 | | const char *pszDialect) override; |
305 | | virtual void ReleaseResultSet(OGRLayer *poResultsSet) override; |
306 | | |
307 | | static bool CheckHeader(const char *pszStr); |
308 | | }; |
309 | | |
310 | | #endif /* OGR_GML_H_INCLUDED */ |