QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 QgsGmlFeatureClass() = default;
46 QgsGmlFeatureClass( const QString &name, const QString &path );
47
48 QList<QgsField> &fields() { return mFields; }
49
50 int fieldIndex( const QString &name );
51
52 QString path() const { return mPath; }
53
54 QStringList &geometryAttributes() { return mGeometryAttributes; }
55
56 private:
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
84class CORE_EXPORT QgsGmlSchema : public QObject
85{
86 Q_OBJECT
87 public:
89
91 bool parseXSD( const QByteArray &xml );
92
100 bool guessSchema( const QByteArray &data );
101
103 QStringList typeNames() const;
104
106 QList<QgsField> fields( const QString &typeName );
107
109 QStringList geometryAttributes( const QString &typeName );
110
112 QgsError error() const { return mError; }
113
114 private:
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 ) { static_cast<QgsGmlSchema *>( data )->startElement( el, attr ); }
131 static void end( void *data, const XML_Char *el ) { static_cast<QgsGmlSchema *>( data )->endElement( el ); }
132 static void chars( void *data, const XML_Char *chars, int len ) { static_cast<QgsGmlSchema *>( data )->characters( chars, len ); }
133 // Add attribute or reset its type according to value of current feature
134 void addAttribute( const QString &name, const QString &value );
135
136 //helper routines
137
142 QString readAttribute( const QString &attributeName, const XML_Char **attr ) const;
143
145 QWidget *findMainWindow() const;
146
148 QList<QDomElement> domElements( const QDomElement &element, const QString &path );
149
151 QDomElement domElement( const QDomElement &element, const QString &path );
152
154 QList<QDomElement> domElements( QList<QDomElement> &elements, const QString &attr, const QString &attrVal );
155
157 QDomElement domElement( const QDomElement &element, const QString &path, const QString &attr, const QString &attrVal );
158
160 static QString stripNS( const QString &name );
161
168 QString xsdComplexTypeGmlBaseType( const QDomElement &element, const QString &name );
169
171 bool xsdFeatureClass( const QDomElement &element, const QString &typeName, QgsGmlFeatureClass &featureClass );
172
173
175 ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? None : mParseModeStack.top(); }
176
178 ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? None : mParseModeStack.pop(); }
179
181 //std::stack<ParseMode> mParseModeStack;
182 QStack<ParseMode> mParseModeStack;
184 QString mStringCash;
185 QgsFeature *mCurrentFeature = nullptr;
186 QString mCurrentFeatureId;
187 int mFeatureCount = 0;
188 QString mAttributeName;
190 QString mCoordinateSeparator;
192 QString mTupleSeparator;
193
194 /* Schema information guessed/parsed from GML in getSchema() */
195
197 int mLevel = 0;
198
200 int mSkipLevel;
201
203 QStringList mParsePathStack;
204
205 QString mCurrentFeatureName;
206
207 // List of know geometries (Point, Multipoint,...)
208 QStringList mGeometryTypes;
209
210 /* Feature classes map with element paths as keys */
211 QMap<QString, QgsGmlFeatureClass> mFeatureClassMap;
212
213 /* Error set if something failed */
214 QgsError mError;
215};
216
217#endif
Represents a coordinate reference system (CRS).
A container for error messages.
Definition qgserror.h:83
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
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.