QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
44 QgsGmlFeatureClass() = default;
45 QgsGmlFeatureClass( const QString &name, const QString &path );
46
47 QList<QgsField> &fields() { return mFields; }
48
49 int fieldIndex( const QString &name );
50
51 QString path() const { return mPath; }
52
53 QStringList &geometryAttributes() { return mGeometryAttributes; }
54
55 private:
56
63 QString mName;
64
65 //QString mElementName;
66
68 QString mPath;
69
70 /* Fields */
71 // Do not use QMap to keep original fields order. If it gets to performance,
72 // add a field index map
73 QList<QgsField> mFields;
74
75 /* Geometry attribute */
76 QStringList mGeometryAttributes;
77};
78
83class CORE_EXPORT QgsGmlSchema : public QObject
84{
85 Q_OBJECT
86 public:
88
90 bool parseXSD( const QByteArray &xml );
91
99 bool guessSchema( const QByteArray &data );
100
102 QStringList typeNames() const;
103
105 QList<QgsField> fields( const QString &typeName );
106
108 QStringList geometryAttributes( const QString &typeName );
109
111 QgsError error() const { return mError; }
112
113 private:
114
115 enum ParseMode
116 {
117 None,
118 BoundingBox,
119 FeatureMembers, // gml:featureMembers
120 FeatureMember, // gml:featureMember
121 Feature, // feature element containing attrs and geo (inside gml:featureMember)
122 Attribute,
123 Geometry
124 };
125
127 void startElement( const XML_Char *el, const XML_Char **attr );
128 void endElement( const XML_Char *el );
129 void characters( const XML_Char *chars, int len );
130 static void start( void *data, const XML_Char *el, const XML_Char **attr )
131 {
132 static_cast<QgsGmlSchema *>( data )->startElement( el, attr );
133 }
134 static void end( void *data, const XML_Char *el )
135 {
136 static_cast<QgsGmlSchema *>( data )->endElement( el );
137 }
138 static void chars( void *data, const XML_Char *chars, int len )
139 {
140 static_cast<QgsGmlSchema *>( data )->characters( chars, len );
141 }
142 // Add attribute or reset its type according to value of current feature
143 void addAttribute( const QString &name, const QString &value );
144
145 //helper routines
146
151 QString readAttribute( const QString &attributeName, const XML_Char **attr ) const;
152
154 QWidget *findMainWindow() const;
155
157 QList<QDomElement> domElements( const QDomElement &element, const QString &path );
158
160 QDomElement domElement( const QDomElement &element, const QString &path );
161
163 QList<QDomElement> domElements( QList<QDomElement> &elements, const QString &attr, const QString &attrVal );
164
166 QDomElement domElement( const QDomElement &element, const QString &path, const QString &attr, const QString &attrVal );
167
169 QString stripNS( const QString &name );
170
177 QString xsdComplexTypeGmlBaseType( const QDomElement &element, const QString &name );
178
180 bool xsdFeatureClass( const QDomElement &element, const QString &typeName, QgsGmlFeatureClass &featureClass );
181
182
184 ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? None : mParseModeStack.top(); }
185
187 ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? None : mParseModeStack.pop(); }
188
190 //std::stack<ParseMode> mParseModeStack;
191 QStack<ParseMode> mParseModeStack;
193 QString mStringCash;
194 QgsFeature *mCurrentFeature = nullptr;
195 QString mCurrentFeatureId;
196 int mFeatureCount = 0;
197 QString mAttributeName;
199 QString mCoordinateSeparator;
201 QString mTupleSeparator;
202
203 /* Schema information guessed/parsed from GML in getSchema() */
204
206 int mLevel = 0;
207
209 int mSkipLevel;
210
212 QStringList mParsePathStack;
213
214 QString mCurrentFeatureName;
215
216 // List of know geometries (Point, Multipoint,...)
217 QStringList mGeometryTypes;
218
219 /* Feature classes map with element paths as keys */
220 QMap<QString, QgsGmlFeatureClass> mFeatureClassMap;
221
222 /* Error set if something failed */
223 QgsError mError;
224};
225
226#endif
This class represents a coordinate reference system (CRS).
A container for error messages.
Definition qgserror.h:81
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Description of feature class in GML.
QString path() const
QStringList & geometryAttributes()
QList< QgsField > & fields()
QgsGmlFeatureClass()=default
QgsError error() const
Gets error if parseXSD() or guessSchema() failed.
A rectangle specified with double values.
const QString & typeName