1 : /******************************************************************************
2 : * $Id: gmlreader.h 25120 2012-10-13 22:38:57Z rouault $
3 : *
4 : * Project: GML Reader
5 : * Purpose: Public Declarations for OGR free GML Reader code.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2002, Frank Warmerdam
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 OR
22 : * 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 _GMLREADER_H_INCLUDED
31 : #define _GMLREADER_H_INCLUDED
32 :
33 : #include "cpl_port.h"
34 : #include "cpl_vsi.h"
35 : #include "cpl_minixml.h"
36 :
37 : #include <vector>
38 :
39 : typedef enum {
40 : GMLPT_Untyped = 0,
41 : GMLPT_String = 1,
42 : GMLPT_Integer = 2,
43 : GMLPT_Real = 3,
44 : GMLPT_Complex = 4,
45 : GMLPT_StringList = 5,
46 : GMLPT_IntegerList = 6,
47 : GMLPT_RealList = 7
48 : } GMLPropertyType;
49 :
50 : /************************************************************************/
51 : /* GMLPropertyDefn */
52 : /************************************************************************/
53 :
54 : typedef struct
55 : {
56 : int nSubProperties;
57 : char** papszSubProperties;
58 : char* aszSubProperties[2]; /* Optimization in the case of nSubProperties == 1 */
59 : } GMLProperty;
60 :
61 : class CPL_DLL GMLPropertyDefn
62 : {
63 : char *m_pszName;
64 : GMLPropertyType m_eType;
65 : int m_nWidth;
66 : int m_nPrecision;
67 : char *m_pszSrcElement;
68 : size_t m_nSrcElementLen;
69 : int m_nIndex;
70 :
71 : public:
72 :
73 : GMLPropertyDefn( const char *pszName, const char *pszSrcElement=NULL );
74 : ~GMLPropertyDefn();
75 :
76 152427 : const char *GetName() const { return m_pszName; }
77 :
78 59290 : GMLPropertyType GetType() const { return m_eType; }
79 1774 : void SetType( GMLPropertyType eType ) { m_eType = eType; }
80 1794 : void SetWidth( int nWidth) { m_nWidth = nWidth; }
81 2606 : int GetWidth() const { return m_nWidth; }
82 764 : void SetPrecision( int nPrecision) { m_nPrecision = nPrecision; }
83 693 : int GetPrecision() const { return m_nPrecision; }
84 : void SetSrcElement( const char *pszSrcElement );
85 727988 : const char *GetSrcElement() const { return m_pszSrcElement; }
86 12066 : size_t GetSrcElementLen() const { return m_nSrcElementLen; }
87 753 : void SetAttributeIndex( int nIndex ) { m_nIndex = nIndex; }
88 : int GetAttributeIndex() const { return m_nIndex; }
89 :
90 : void AnalysePropertyValue( const GMLProperty* psGMLProperty );
91 :
92 : static bool IsSimpleType( GMLPropertyType eType )
93 : { return eType == GMLPT_String || eType == GMLPT_Integer || eType == GMLPT_Real; }
94 : };
95 :
96 : /************************************************************************/
97 : /* GMLFeatureClass */
98 : /************************************************************************/
99 : class CPL_DLL GMLFeatureClass
100 : {
101 : char *m_pszName;
102 : char *m_pszElementName;
103 : int n_nNameLen;
104 : int n_nElementNameLen;
105 : char *m_pszGeometryElement;
106 : int m_nPropertyCount;
107 : GMLPropertyDefn **m_papoProperty;
108 :
109 : int m_bSchemaLocked;
110 :
111 : int m_nFeatureCount;
112 :
113 : char *m_pszExtraInfo;
114 :
115 : int m_bHaveExtents;
116 : double m_dfXMin;
117 : double m_dfXMax;
118 : double m_dfYMin;
119 : double m_dfYMax;
120 :
121 : int m_nGeometryType;
122 : int m_nGeometryIndex;
123 :
124 : char *m_pszSRSName;
125 : int m_bSRSNameConsistant;
126 :
127 : public:
128 : GMLFeatureClass( const char *pszName = "" );
129 : ~GMLFeatureClass();
130 :
131 : const char *GetElementName() const;
132 : size_t GetElementNameLen() const;
133 : void SetElementName( const char *pszElementName );
134 :
135 2133 : const char *GetGeometryElement() const { return m_pszGeometryElement; }
136 : void SetGeometryElement( const char *pszElementName );
137 :
138 9754 : const char *GetName() const { return m_pszName; }
139 : void SetName(const char* pszNewName);
140 836999 : int GetPropertyCount() const { return m_nPropertyCount; }
141 : GMLPropertyDefn *GetProperty( int iIndex ) const;
142 : int GetPropertyIndex( const char *pszName ) const;
143 2029 : GMLPropertyDefn *GetProperty( const char *pszName ) const
144 2029 : { return GetProperty( GetPropertyIndex(pszName) ); }
145 : int GetPropertyIndexBySrcElement( const char *pszElement, int nLen ) const;
146 :
147 : int AddProperty( GMLPropertyDefn * );
148 :
149 141237 : int IsSchemaLocked() const { return m_bSchemaLocked; }
150 345 : void SetSchemaLocked( int bLock ) { m_bSchemaLocked = bLock; }
151 :
152 : const char *GetExtraInfo();
153 : void SetExtraInfo( const char * );
154 :
155 : int GetFeatureCount();
156 : void SetFeatureCount( int );
157 :
158 59 : int HasExtents() const { return m_bHaveExtents; }
159 : void SetExtents( double dfXMin, double dfXMax,
160 : double dFYMin, double dfYMax );
161 : int GetExtents( double *pdfXMin, double *pdfXMax,
162 : double *pdFYMin, double *pdfYMax );
163 :
164 780 : int GetGeometryType() const { return m_nGeometryType; }
165 692 : void SetGeometryType( int nNewType ) { m_nGeometryType = nNewType; }
166 592 : int GetGeometryAttributeIndex() const { return m_nGeometryIndex; }
167 191 : void SetGeometryAttributeIndex( int nGeometryIndex ) { m_nGeometryIndex = nGeometryIndex; }
168 :
169 : void SetSRSName( const char* pszSRSName );
170 : void MergeSRSName( const char* pszSRSName );
171 344 : const char *GetSRSName() { return m_pszSRSName; }
172 :
173 : CPLXMLNode *SerializeToXML();
174 : int InitializeFromXML( CPLXMLNode * );
175 : };
176 :
177 : /************************************************************************/
178 : /* GMLFeature */
179 : /************************************************************************/
180 :
181 : class CPL_DLL GMLFeature
182 : {
183 : GMLFeatureClass *m_poClass;
184 : char *m_pszFID;
185 :
186 : int m_nPropertyCount;
187 : GMLProperty *m_pasProperties;
188 :
189 : int m_nGeometryCount;
190 : CPLXMLNode **m_papsGeometry; /* NULL-terminated. Alias to m_apsGeometry if m_nGeometryCount <= 1 */
191 : CPLXMLNode *m_apsGeometry[2]; /* NULL-terminated */
192 :
193 : // string list of named non-schema properties - used by NAS driver.
194 : char **m_papszOBProperties;
195 :
196 : public:
197 : GMLFeature( GMLFeatureClass * );
198 : ~GMLFeature();
199 :
200 155435 : GMLFeatureClass*GetClass() const { return m_poClass; }
201 :
202 : void SetGeometryDirectly( CPLXMLNode* psGeom );
203 : void AddGeometry( CPLXMLNode* psGeom );
204 14823 : const CPLXMLNode* const * GetGeometryList() const { return m_papsGeometry; }
205 :
206 : void SetPropertyDirectly( int i, char *pszValue );
207 :
208 57477 : const GMLProperty*GetProperty( int i ) const { return (i < m_nPropertyCount) ? &m_pasProperties[i] : NULL; }
209 :
210 606 : const char *GetFID() const { return m_pszFID; }
211 : void SetFID( const char *pszFID );
212 :
213 : void Dump( FILE *fp );
214 :
215 : // Out of Band property handling - special stuff like relations for NAS.
216 : void AddOBProperty( const char *pszName, const char *pszValue );
217 : const char *GetOBProperty( const char *pszName );
218 : char **GetOBProperties();
219 : };
220 :
221 : /************************************************************************/
222 : /* IGMLReader */
223 : /************************************************************************/
224 : class CPL_DLL IGMLReader
225 120 : {
226 : public:
227 : virtual ~IGMLReader();
228 :
229 : virtual int IsClassListLocked() const = 0;
230 : virtual void SetClassListLocked( int bFlag ) = 0;
231 :
232 : virtual void SetSourceFile( const char *pszFilename ) = 0;
233 0 : virtual void SetFP( VSILFILE* fp ) { }
234 : virtual const char* GetSourceFileName() = 0;
235 :
236 : virtual int GetClassCount() const = 0;
237 : virtual GMLFeatureClass *GetClass( int i ) const = 0;
238 : virtual GMLFeatureClass *GetClass( const char *pszName ) const = 0;
239 :
240 : virtual int AddClass( GMLFeatureClass *poClass ) = 0;
241 : virtual void ClearClasses() = 0;
242 :
243 : virtual GMLFeature *NextFeature() = 0;
244 : virtual void ResetReading() = 0;
245 :
246 : virtual int LoadClasses( const char *pszFile = NULL ) = 0;
247 : virtual int SaveClasses( const char *pszFile = NULL ) = 0;
248 :
249 : virtual int ResolveXlinks( const char *pszFile,
250 : int* pbOutIsTempFile,
251 : char **papszSkip = NULL,
252 : const int bStrict = FALSE ) = 0;
253 :
254 : virtual int HugeFileResolver( const char *pszFile,
255 : int pbSqlitIsTempFile,
256 : int iSqliteCacheMB ) = 0;
257 :
258 : virtual int PrescanForSchema( int bGetExtents = TRUE ) = 0;
259 : virtual int PrescanForTemplate( void ) = 0;
260 :
261 : virtual int HasStoppedParsing() = 0;
262 :
263 0 : virtual void SetGlobalSRSName( const char* pszGlobalSRSName ) {}
264 : virtual const char* GetGlobalSRSName() = 0;
265 : virtual int CanUseGlobalSRSName() = 0;
266 :
267 : virtual int SetFilteredClassName(const char* pszClassName) = 0;
268 : virtual const char* GetFilteredClassName() = 0;
269 :
270 0 : virtual int IsSequentialLayers() const { return FALSE; }
271 : };
272 :
273 : IGMLReader *CreateGMLReader(int bUseExpatParserPreferably,
274 : int bInvertAxisOrderIfLatLong,
275 : int bConsiderEPSGAsURN,
276 : int bGetSecondaryGeometryOption);
277 :
278 :
279 : #endif /* _GMLREADER_H_INCLUDED */
|