QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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 <expat.h>
19#include <list>
20#include <set>
21#include <stack>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
25#include "qgserror.h"
26#include "qgsfields.h"
27
28#include <QByteArray>
29#include <QDomElement>
30#include <QPair>
31#include <QStack>
32#include <QStringList>
33
34class QgsRectangle;
36class QgsFeature;
37
42class CORE_EXPORT QgsGmlFeatureClass
43{
44 public:
45
46 QgsGmlFeatureClass() = default;
47 QgsGmlFeatureClass( const QString &name, const QString &path );
48
49 QList<QgsField> &fields() { return mFields; }
50
51 int fieldIndex( const QString &name );
52
53 QString path() const { return mPath; }
54
55 QStringList &geometryAttributes() { return mGeometryAttributes; }
56
57 private:
58
65 QString mName;
66
67 //QString mElementName;
68
70 QString mPath;
71
72 /* Fields */
73 // Do not use QMap to keep original fields order. If it gets to performance,
74 // add a field index map
75 QList<QgsField> mFields;
76
77 /* Geometry attribute */
78 QStringList mGeometryAttributes;
79};
80
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 static 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
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
QString path() const
QStringList & geometryAttributes()
QList< QgsField > & fields()
QgsGmlFeatureClass()=default
bool parseXSD(const QByteArray &xml)
Gets fields info from XSD.
QList< QgsField > fields(const QString &typeName)
Gets fields for type/class name parsed from GML or XSD.
QStringList geometryAttributes(const QString &typeName)
Gets list of geometry attributes for type/class name.
bool guessSchema(const QByteArray &data)
Guess GML schema from data if XSD does not exist.
QStringList typeNames() const
Gets list of dot separated paths to feature classes parsed from GML or XSD.
QgsError error() const
Gets error if parseXSD() or guessSchema() failed.
A rectangle specified with double values.