QGIS API Documentation  2.12.0-Lyon
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 
62  int getFeatures( const QString& uri,
63  QGis::WkbType* wkbType,
64  QgsRectangle* extent = 0,
65  const QString& userName = QString(),
66  const QString& password = QString(),
67  const QString& authcfg = QString() );
68 
72  int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
73 
75  QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; }
76 
78  QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; }
79 
82  QgsCoordinateReferenceSystem crs() const;
83 
84  private slots:
85 
86  void setFinished();
87 
89  void handleProgressEvent( qint64 progress, qint64 totalSteps );
90 
91  signals:
92  void dataReadProgress( int progress );
93  void totalStepsUpdate( int totalSteps );
94  //also emit signal with progress and totalSteps together (this is better for the status message)
95  void dataProgressAndSteps( int progress, int totalSteps );
96 
97  private:
98 
99  enum ParseMode
100  {
101  none,
102  boundingBox,
103  feature, // feature element containing attrs and geo (inside gml:featureMember)
104  attribute,
105  geometry,
106  coordinate,
107  posList,
108  multiPoint,
109  multiLine,
110  multiPolygon
111  };
112 
114  void startElement( const XML_Char* el, const XML_Char** attr );
115  void endElement( const XML_Char* el );
116  void characters( const XML_Char* chars, int len );
117  static void start( void* data, const XML_Char* el, const XML_Char** attr )
118  {
119  static_cast<QgsGml*>( data )->startElement( el, attr );
120  }
121  static void end( void* data, const XML_Char* el )
122  {
123  static_cast<QgsGml*>( data )->endElement( el );
124  }
125  static void chars( void* data, const XML_Char* chars, int len )
126  {
127  static_cast<QgsGml*>( data )->characters( chars, len );
128  }
129 
130  // Set current feature attribute
131  void setAttribute( const QString& name, const QString& value );
132 
133  //helper routines
134 
140  int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const;
146  QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
149  int createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const;
155  int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const;
156 
163  int pointsFromPosListString( QList<QgsPoint>& points, const QString& coordString, int dimension ) const;
164 
165  int pointsFromString( QList<QgsPoint>& points, const QString& coordString ) const;
166  int getPointWKB( unsigned char** wkb, int* size, const QgsPoint& ) const;
167  int getLineWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& lineCoordinates ) const;
168  int getRingWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& ringCoordinates ) const;
174  int createMultiLineFromFragments();
175  int createMultiPointFromFragments();
176  int createPolygonFromFragments();
177  int createMultiPolygonFromFragments();
179  int totalWKBFragmentSize() const;
180 
182  QWidget* findMainWindow() const;
188  void calculateExtentFromFeatures();
189 
191  ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); }
192 
194  ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); }
195 
196  QString mTypeName;
197  QString mUri;
198  //results are members such that handler routines are able to manipulate them
200  QgsRectangle mExtent;
202  //QMap<QgsFeatureId, QgsFeature* > &mFeatures;
204  //QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures;
205 
207  //QMap<QgsFeatureId, QString > &mIdMap;
209  //QMap<QString, QMap<QgsFeatureId, QString > > mIdMap;
211  QString mGeometryAttribute;
212  //const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
213  QMap<QString, QPair<int, QgsField> > mThematicAttributes;
214  QGis::WkbType* mWkbType;
216  bool mFinished;
218  QStack<ParseMode> mParseModeStack;
220  QString mStringCash;
221  QgsFeature* mCurrentFeature;
222  QVector<QVariant> mCurrentAttributes; //attributes of current feature
223  QString mCurrentFeatureId;
224  int mFeatureCount;
226  unsigned char* mCurrentWKB;
228  int mCurrentWKBSize;
229  QgsRectangle mCurrentExtent;
234  QList< QList<unsigned char*> > mCurrentWKBFragments;
236  QList< QList<int> > mCurrentWKBFragmentSizes;
237  QString mAttributeName;
238  QgsApplication::endian_t mEndian;
240  QString mCoordinateSeparator;
242  QString mTupleSeparator;
244  int mDimension;
246  ParseMode mCoorMode;
248  int mEpsg;
249 };
250 
251 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
enum QgsApplication::ENDIAN endian_t
Constants for endian-ness.
Container of fields for a vector layer.
Definition: qgsfield.h:177
WkbType
Used for symbology operations.
Definition: qgis.h:56
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
QMap< QgsFeatureId, QString > idsMap() const
Get feature ids map.
Definition: qgsgml.h:78
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:63
QMap< QgsFeatureId, QgsFeature * > featuresMap() const
Get parsed features for given type name.
Definition: qgsgml.h:75
Class for storing a coordinate reference system (CRS)