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