QGIS API Documentation  2.13.0-Master
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 
29 #include <QPair>
30 #include <QByteArray>
31 #include <QDomElement>
32 #include <QStringList>
33 #include <QStack>
34 
35 class QgsRectangle;
36 
41 class CORE_EXPORT QgsGml : public QObject
42 {
43  Q_OBJECT
44  public:
45  QgsGml(
46  const QString& typeName,
47  const QString& geometryAttribute,
48  const QgsFields & fields );
49 
50  ~QgsGml();
51 
63  int getFeatures( const QString& uri,
64  QGis::WkbType* wkbType,
65  QgsRectangle* extent = nullptr,
66  const QString& userName = QString(),
67  const QString& password = QString(),
68  const QString& authcfg = QString() );
69 
73  int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = nullptr );
74 
76  QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; }
77 
79  QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; }
80 
83  QgsCoordinateReferenceSystem crs() const;
84 
85  private slots:
86 
87  void setFinished();
88 
90  void handleProgressEvent( qint64 progress, qint64 totalSteps );
91 
92  signals:
93  void dataReadProgress( int progress );
94  void totalStepsUpdate( int totalSteps );
95  //also emit signal with progress and totalSteps together (this is better for the status message)
96  void dataProgressAndSteps( int progress, int totalSteps );
97 
98  private:
99 
100  enum ParseMode
101  {
102  none,
103  boundingBox,
104  feature, // feature element containing attrs and geo (inside gml:featureMember)
105  attribute,
106  geometry,
107  coordinate,
108  posList,
109  multiPoint,
110  multiLine,
111  multiPolygon
112  };
113 
115  void startElement( const XML_Char* el, const XML_Char** attr );
116  void endElement( const XML_Char* el );
117  void characters( const XML_Char* chars, int len );
118  static void start( void* data, const XML_Char* el, const XML_Char** attr )
119  {
120  static_cast<QgsGml*>( data )->startElement( el, attr );
121  }
122  static void end( void* data, const XML_Char* el )
123  {
124  static_cast<QgsGml*>( data )->endElement( el );
125  }
126  static void chars( void* data, const XML_Char* chars, int len )
127  {
128  static_cast<QgsGml*>( data )->characters( chars, len );
129  }
130 
131  // Set current feature attribute
132  void setAttribute( const QString& name, const QString& value );
133 
134  //helper routines
135 
141  int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const;
147  QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
150  int createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const;
156  int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const;
157 
164  int pointsFromPosListString( QList<QgsPoint>& points, const QString& coordString, int dimension ) const;
165 
166  int pointsFromString( QList<QgsPoint>& points, const QString& coordString ) const;
167  int getPointWKB( unsigned char** wkb, int* size, const QgsPoint& ) const;
168  int getLineWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& lineCoordinates ) const;
169  int getRingWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& ringCoordinates ) const;
175  int createMultiLineFromFragments();
176  int createMultiPointFromFragments();
177  int createPolygonFromFragments();
178  int createMultiPolygonFromFragments();
180  int totalWKBFragmentSize() const;
181 
183  QWidget* findMainWindow() const;
189  void calculateExtentFromFeatures();
190 
192  ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); }
193 
195  ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); }
196 
197  QString mTypeName;
198  QString mUri;
199  //results are members such that handler routines are able to manipulate them
201  QgsRectangle mExtent;
203  //QMap<QgsFeatureId, QgsFeature* > &mFeatures;
205  //QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures;
206 
208  //QMap<QgsFeatureId, QString > &mIdMap;
210  //QMap<QString, QMap<QgsFeatureId, QString > > mIdMap;
212  QString mGeometryAttribute;
213  //const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
214  QMap<QString, QPair<int, QgsField> > mThematicAttributes;
215  QGis::WkbType* mWkbType;
217  bool mFinished;
219  QStack<ParseMode> mParseModeStack;
221  QString mStringCash;
222  QgsFeature* mCurrentFeature;
223  QVector<QVariant> mCurrentAttributes; //attributes of current feature
224  QString mCurrentFeatureId;
225  int mFeatureCount;
227  unsigned char* mCurrentWKB;
229  int mCurrentWKBSize;
230  QgsRectangle mCurrentExtent;
235  QList< QList<unsigned char*> > mCurrentWKBFragments;
237  QList< QList<int> > mCurrentWKBFragmentSizes;
238  QString mAttributeName;
239  QgsApplication::endian_t mEndian;
241  QString mCoordinateSeparator;
243  QString mTupleSeparator;
245  int mDimension;
247  ParseMode mCoorMode;
249  int mEpsg;
250 };
251 
252 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Container of fields for a vector layer.
Definition: qgsfield.h:189
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:79
endian_t
Constants for endian-ness.
This class reads data from a WFS server or alternatively from a GML file.
Definition: qgsgml.h:41
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:76
Class for storing a coordinate reference system (CRS)