QGIS API Documentation  2.14.0-Essen
qgsgml.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgml.h
3  ---------------------
4  begin : February 2013
5  copyright : (C) 2013 by Radim Blazek
6  email : radim dot blazek at gmail 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 QGSGML_H
16 #define QGSGML_H
17 
18 #include <expat.h>
19 #include "qgis.h"
20 #include "qgsapplication.h"
22 #include "qgsdataprovider.h"
23 #include "qgsfeature.h"
24 #include "qgsfield.h"
25 #include "qgslogger.h"
26 #include "qgspoint.h"
27 #include "qgsrectangle.h"
28 #include "qgswkbptr.h"
29 
30 #include <QPair>
31 #include <QByteArray>
32 #include <QDomElement>
33 #include <QStringList>
34 #include <QStack>
35 
36 class QgsRectangle;
37 
42 class CORE_EXPORT QgsGml : public QObject
43 {
44  Q_OBJECT
45  public:
46  QgsGml(
47  const QString& typeName,
48  const QString& geometryAttribute,
49  const QgsFields & fields );
50 
51  ~QgsGml();
52 
64  int getFeatures( const QString& uri,
65  QGis::WkbType* wkbType,
66  QgsRectangle* extent = nullptr,
67  const QString& userName = QString(),
68  const QString& password = QString(),
69  const QString& authcfg = QString() );
70 
74  int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = nullptr );
75 
77  QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; }
78 
80  QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; }
81 
84  QgsCoordinateReferenceSystem crs() const;
85 
86  private slots:
87 
88  void setFinished();
89 
91  void handleProgressEvent( qint64 progress, qint64 totalSteps );
92 
93  signals:
94  void dataReadProgress( int progress );
95  void totalStepsUpdate( int totalSteps );
96  //also emit signal with progress and totalSteps together (this is better for the status message)
97  void dataProgressAndSteps( int progress, int totalSteps );
98 
99  private:
100 
101  enum ParseMode
102  {
103  none,
104  boundingBox,
105  feature, // feature element containing attrs and geo (inside gml:featureMember)
106  attribute,
107  geometry,
108  coordinate,
109  posList,
110  multiPoint,
111  multiLine,
112  multiPolygon
113  };
114 
116  void startElement( const XML_Char* el, const XML_Char** attr );
117  void endElement( const XML_Char* el );
118  void characters( const XML_Char* chars, int len );
119  static void start( void* data, const XML_Char* el, const XML_Char** attr )
120  {
121  static_cast<QgsGml*>( data )->startElement( el, attr );
122  }
123  static void end( void* data, const XML_Char* el )
124  {
125  static_cast<QgsGml*>( data )->endElement( el );
126  }
127  static void chars( void* data, const XML_Char* chars, int len )
128  {
129  static_cast<QgsGml*>( data )->characters( chars, len );
130  }
131 
132  // Set current feature attribute
133  void setAttribute( const QString& name, const QString& value );
134 
135  //helper routines
136 
142  int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const;
148  QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
151  int createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const;
157  int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const;
158 
165  int pointsFromPosListString( QList<QgsPoint>& points, const QString& coordString, int dimension ) const;
166 
167  int pointsFromString( QList<QgsPoint>& points, const QString& coordString ) const;
168  int getPointWKB( QgsWkbPtr &wkbPtr, const QgsPoint& ) const;
169  int getLineWKB( QgsWkbPtr &wkbPtr, const QList<QgsPoint>& lineCoordinates ) const;
170  int getRingWKB( QgsWkbPtr &wkbPtr, const QList<QgsPoint>& ringCoordinates ) const;
176  int createMultiLineFromFragments();
177  int createMultiPointFromFragments();
178  int createPolygonFromFragments();
179  int createMultiPolygonFromFragments();
181  int totalWKBFragmentSize() const;
182 
184  QWidget* findMainWindow() const;
190  void calculateExtentFromFeatures();
191 
193  ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); }
194 
196  ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); }
197 
198  QString mTypeName;
199  QString mUri;
200  //results are members such that handler routines are able to manipulate them
202  QgsRectangle mExtent;
204  //QMap<QgsFeatureId, QgsFeature* > &mFeatures;
206  //QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures;
207 
209  //QMap<QgsFeatureId, QString > &mIdMap;
211  //QMap<QString, QMap<QgsFeatureId, QString > > mIdMap;
213  QString mGeometryAttribute;
214  //const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
215  QMap<QString, QPair<int, QgsField> > mThematicAttributes;
216  QGis::WkbType* mWkbType;
218  bool mFinished;
220  QStack<ParseMode> mParseModeStack;
222  QString mStringCash;
223  QgsFeature* mCurrentFeature;
224  QVector<QVariant> mCurrentAttributes; //attributes of current feature
225  QString mCurrentFeatureId;
226  int mFeatureCount;
228  QgsWkbPtr mCurrentWKB;
229  QgsRectangle mCurrentExtent;
234  QList< QList<QgsWkbPtr> > mCurrentWKBFragments;
235  QString mAttributeName;
236  char mEndian;
238  QString mCoordinateSeparator;
240  QString mTupleSeparator;
242  int mDimension;
244  ParseMode mCoorMode;
246  int mEpsg;
247 };
248 
249 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Container of fields for a vector layer.
Definition: qgsfield.h:187
WkbType
Used for symbology operations.
Definition: qgis.h:57
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QMap< QgsFeatureId, QString > idsMap() const
Get feature ids map.
Definition: qgsgml.h:80
This class reads data from a WFS server or alternatively from a GML file.
Definition: qgsgml.h:42
A class to represent a point.
Definition: qgspoint.h:65
QMap< QgsFeatureId, QgsFeature * > featuresMap() const
Get parsed features for given type name.
Definition: qgsgml.h:77
Class for storing a coordinate reference system (CRS)