QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsgmlschema.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgmlschema.h
3 --------------------------------------
4 Date : Sun Sep 16 12:19:55 AKDT 2007
5 Copyright : (C) 2007 by Gary E. Sherman
6 Email : sherman at mrcc dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSGMLSCHEMA_H
16#define QGSGMLSCHEMA_H
17
18#include "qgis_core.h"
19#include <expat.h>
20#include "qgis_sip.h"
21#include "qgserror.h"
22#include "qgsfields.h"
23#include <list>
24#include <set>
25#include <stack>
26#include <QPair>
27#include <QByteArray>
28#include <QDomElement>
29#include <QStringList>
30#include <QStack>
31
32class QgsRectangle;
34class QgsFeature;
35
40class CORE_EXPORT QgsGmlFeatureClass
41{
42 public:
43
47 QgsGmlFeatureClass() = default;
48 QgsGmlFeatureClass( const QString &name, const QString &path );
49
50 QList<QgsField> &fields() { return mFields; }
51
52 int fieldIndex( const QString &name );
53
54 QString path() const { return mPath; }
55
56 QStringList &geometryAttributes() { return mGeometryAttributes; }
57
58 private:
59
66 QString mName;
67
68 //QString mElementName;
69
71 QString mPath;
72
73 /* Fields */
74 // Do not use QMap to keep original fields order. If it gets to performance,
75 // add a field index map
76 QList<QgsField> mFields;
77
78 /* Geometry attribute */
79 QStringList mGeometryAttributes;
80};
81
86class CORE_EXPORT QgsGmlSchema : public QObject
87{
88 Q_OBJECT
89 public:
91
93 bool parseXSD( const QByteArray &xml );
94
102 bool guessSchema( const QByteArray &data );
103
105 QStringList typeNames() const;
106
108 QList<QgsField> fields( const QString &typeName );
109
111 QStringList geometryAttributes( const QString &typeName );
112
114 QgsError error() const { return mError; }
115
116 private:
117
118 enum ParseMode
119 {
120 None,
121 BoundingBox,
122 FeatureMembers, // gml:featureMembers
123 FeatureMember, // gml:featureMember
124 Feature, // feature element containing attrs and geo (inside gml:featureMember)
125 Attribute,
126 Geometry
127 };
128
130 void startElement( const XML_Char *el, const XML_Char **attr );
131 void endElement( const XML_Char *el );
132 void characters( const XML_Char *chars, int len );
133 static void start( void *data, const XML_Char *el, const XML_Char **attr )
134 {
135 static_cast<QgsGmlSchema *>( data )->startElement( el, attr );
136 }
137 static void end( void *data, const XML_Char *el )
138 {
139 static_cast<QgsGmlSchema *>( data )->endElement( el );
140 }
141 static void chars( void *data, const XML_Char *chars, int len )
142 {
143 static_cast<QgsGmlSchema *>( data )->characters( chars, len );
144 }
145 // Add attribute or reset its type according to value of current feature
146 void addAttribute( const QString &name, const QString &value );
147
148 //helper routines
149
154 QString readAttribute( const QString &attributeName, const XML_Char **attr ) const;
155
157 QWidget *findMainWindow() const;
158
160 QList<QDomElement> domElements( const QDomElement &element, const QString &path );
161
163 QDomElement domElement( const QDomElement &element, const QString &path );
164
166 QList<QDomElement> domElements( QList<QDomElement> &elements, const QString &attr, const QString &attrVal );
167
169 QDomElement domElement( const QDomElement &element, const QString &path, const QString &attr, const QString &attrVal );
170
172 QString stripNS( const QString &name );
173
180 QString xsdComplexTypeGmlBaseType( const QDomElement &element, const QString &name );
181
183 bool xsdFeatureClass( const QDomElement &element, const QString &typeName, QgsGmlFeatureClass &featureClass );
184
185
187 ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? None : mParseModeStack.top(); }
188
190 ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? None : mParseModeStack.pop(); }
191
193 //std::stack<ParseMode> mParseModeStack;
194 QStack<ParseMode> mParseModeStack;
196 QString mStringCash;
197 QgsFeature *mCurrentFeature = nullptr;
198 QString mCurrentFeatureId;
199 int mFeatureCount = 0;
200 QString mAttributeName;
202 QString mCoordinateSeparator;
204 QString mTupleSeparator;
205
206 /* Schema information guessed/parsed from GML in getSchema() */
207
209 int mLevel = 0;
210
212 int mSkipLevel;
213
215 QStringList mParsePathStack;
216
217 QString mCurrentFeatureName;
218
219 // List of know geometries (Point, Multipoint,...)
220 QStringList mGeometryTypes;
221
222 /* Feature classes map with element paths as keys */
223 QMap<QString, QgsGmlFeatureClass> mFeatureClassMap;
224
225 /* Error set if something failed */
226 QgsError mError;
227};
228
229#endif
This class represents a coordinate reference system (CRS).
QgsError is container for error messages (report).
Definition: qgserror.h:81
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Description of feature class in GML.
Definition: qgsgmlschema.h:41
QString path() const
Definition: qgsgmlschema.h:54
QStringList & geometryAttributes()
Definition: qgsgmlschema.h:56
QList< QgsField > & fields()
Definition: qgsgmlschema.h:50
QgsGmlFeatureClass()=default
Constructor for QgsGmlFeatureClass.
QgsError error() const
Gets error if parseXSD() or guessSchema() failed.
Definition: qgsgmlschema.h:114
A rectangle specified with double values.
Definition: qgsrectangle.h:42
const QString & typeName