1 : /******************************************************************************
2 : * $Id: gmlreader.h 20029 2010-07-11 18:38:23Z 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 : typedef enum {
37 : GMLPT_Untyped = 0,
38 : GMLPT_String = 1,
39 : GMLPT_Integer = 2,
40 : GMLPT_Real = 3,
41 : GMLPT_Complex = 4,
42 : GMLPT_StringList = 5,
43 : GMLPT_IntegerList = 6,
44 : GMLPT_RealList = 7
45 : } GMLPropertyType;
46 :
47 : /************************************************************************/
48 : /* GMLPropertyDefn */
49 : /************************************************************************/
50 : class CPL_DLL GMLPropertyDefn
51 : {
52 : char *m_pszName;
53 : GMLPropertyType m_eType;
54 : int m_nWidth;
55 : int m_nPrecision;
56 : char *m_pszSrcElement;
57 :
58 : public:
59 :
60 : GMLPropertyDefn( const char *pszName, const char *pszSrcElement=NULL );
61 : ~GMLPropertyDefn();
62 :
63 3029 : const char *GetName() const { return m_pszName; }
64 :
65 80675 : GMLPropertyType GetType() const { return m_eType; }
66 210 : void SetType( GMLPropertyType eType ) { m_eType = eType; }
67 213 : void SetWidth( int nWidth) { m_nWidth = nWidth; }
68 472 : int GetWidth() { return m_nWidth; }
69 4 : void SetPrecision( int nPrecision) { m_nPrecision = nPrecision; }
70 59 : int GetPrecision() { return m_nPrecision; }
71 : void SetSrcElement( const char *pszSrcElement );
72 965936 : const char *GetSrcElement() { return m_pszSrcElement; }
73 :
74 : void AnalysePropertyValue( const char *pszValue,
75 : const char *pszOldValue = NULL );
76 : };
77 :
78 : /************************************************************************/
79 : /* GMLFeatureClass */
80 : /************************************************************************/
81 : class CPL_DLL GMLFeatureClass
82 : {
83 : char *m_pszName;
84 : char *m_pszElementName;
85 : char *m_pszGeometryElement;
86 : int m_nPropertyCount;
87 : GMLPropertyDefn **m_papoProperty;
88 :
89 : int m_bSchemaLocked;
90 :
91 : int m_nFeatureCount;
92 :
93 : char *m_pszExtraInfo;
94 :
95 : int m_bHaveExtents;
96 : double m_dfXMin;
97 : double m_dfXMax;
98 : double m_dfYMin;
99 : double m_dfYMax;
100 :
101 : int m_nGeometryType;
102 :
103 : public:
104 : GMLFeatureClass( const char *pszName = "" );
105 : ~GMLFeatureClass();
106 :
107 : const char *GetElementName() const;
108 : void SetElementName( const char *pszElementName );
109 :
110 73 : const char *GetGeometryElement() const { return m_pszGeometryElement; }
111 : void SetGeometryElement( const char *pszElementName );
112 :
113 1742 : const char *GetName() const { return m_pszName; }
114 1358646 : int GetPropertyCount() const { return m_nPropertyCount; }
115 : GMLPropertyDefn *GetProperty( int iIndex ) const;
116 : int GetPropertyIndex( const char *pszName ) const;
117 278 : GMLPropertyDefn *GetProperty( const char *pszName ) const
118 278 : { return GetProperty( GetPropertyIndex(pszName) ); }
119 :
120 : int AddProperty( GMLPropertyDefn * );
121 :
122 223743 : int IsSchemaLocked() const { return m_bSchemaLocked; }
123 48 : void SetSchemaLocked( int bLock ) { m_bSchemaLocked = bLock; }
124 :
125 : const char *GetExtraInfo();
126 : void SetExtraInfo( const char * );
127 :
128 : int GetFeatureCount();
129 : void SetFeatureCount( int );
130 :
131 : void SetExtents( double dfXMin, double dfXMax,
132 : double dFYMin, double dfYMax );
133 : int GetExtents( double *pdfXMin, double *pdfXMax,
134 : double *pdFYMin, double *pdfYMax );
135 :
136 100 : int GetGeometryType() const { return m_nGeometryType; }
137 61 : void SetGeometryType( int nNewType ) { m_nGeometryType = nNewType; }
138 :
139 : CPLXMLNode *SerializeToXML();
140 : int InitializeFromXML( CPLXMLNode * );
141 : };
142 :
143 : /************************************************************************/
144 : /* GMLFeature */
145 : /************************************************************************/
146 : class CPL_DLL GMLFeature
147 : {
148 : GMLFeatureClass *m_poClass;
149 : char *m_pszFID;
150 :
151 : int m_nPropertyCount;
152 : char **m_papszProperty;
153 :
154 : char *m_pszGeometry;
155 :
156 : // string list of named non-schema properties - used by NAS driver.
157 : char **m_papszOBProperties;
158 :
159 : public:
160 : GMLFeature( GMLFeatureClass * );
161 : ~GMLFeature();
162 :
163 1256814 : GMLFeatureClass*GetClass() const { return m_poClass; }
164 :
165 : void SetGeometryDirectly( char * );
166 143 : const char *GetGeometry() const { return m_pszGeometry; }
167 :
168 : void SetProperty( int i, const char *pszValue );
169 : void SetProperty( const char *pszName, const char *pszValue )
170 : { SetProperty( m_poClass->GetPropertyIndex(pszName), pszValue ); }
171 :
172 : const char *GetProperty( int i ) const;
173 1836 : const char *GetProperty( const char *pszName ) const
174 1836 : { return GetProperty( m_poClass->GetPropertyIndex(pszName) ); }
175 :
176 34 : const char *GetFID() const { return m_pszFID; }
177 : void SetFID( const char *pszFID );
178 :
179 : void Dump( FILE *fp );
180 :
181 : // Out of Band property handling - special stuff like relations for NAS.
182 : void AddOBProperty( const char *pszName, const char *pszValue );
183 : const char *GetOBProperty( const char *pszName );
184 : char **GetOBProperties();
185 : };
186 :
187 : /************************************************************************/
188 : /* IGMLReader */
189 : /************************************************************************/
190 : class CPL_DLL IGMLReader
191 21 : {
192 : public:
193 : virtual ~IGMLReader();
194 :
195 : virtual int IsClassListLocked() const = 0;
196 : virtual void SetClassListLocked( int bFlag ) = 0;
197 :
198 : virtual void SetSourceFile( const char *pszFilename ) = 0;
199 : virtual const char* GetSourceFileName() = 0;
200 :
201 : virtual int GetClassCount() const = 0;
202 : virtual GMLFeatureClass *GetClass( int i ) const = 0;
203 : virtual GMLFeatureClass *GetClass( const char *pszName ) const = 0;
204 :
205 : virtual int AddClass( GMLFeatureClass *poClass ) = 0;
206 : virtual void ClearClasses() = 0;
207 :
208 : virtual GMLFeature *NextFeature() = 0;
209 : virtual void ResetReading() = 0;
210 :
211 : virtual int LoadClasses( const char *pszFile = NULL ) = 0;
212 : virtual int SaveClasses( const char *pszFile = NULL ) = 0;
213 :
214 : virtual int ParseXSD( const char *pszFile ) = 0;
215 :
216 : virtual int ResolveXlinks( const char *pszFile,
217 : int* pbOutIsTempFile,
218 : char **papszSkip = NULL,
219 : const int bStrict = FALSE ) = 0;
220 :
221 : virtual int PrescanForSchema( int bGetExtents = TRUE ) = 0;
222 :
223 : virtual int HasStoppedParsing() = 0;
224 : };
225 :
226 : IGMLReader *CreateGMLReader();
227 :
228 :
229 : #endif /* _GMLREADER_H_INCLUDED */
|