QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
61  int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0, const QString& userName = QString(), const QString& password = QString() );
62 
66  int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
67 
69  QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; }
70 
72  QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; }
73 
76  QgsCoordinateReferenceSystem crs() const;
77 
78  private slots:
79 
80  void setFinished();
81 
83  void handleProgressEvent( qint64 progress, qint64 totalSteps );
84 
85  signals:
86  void dataReadProgress( int progress );
87  void totalStepsUpdate( int totalSteps );
88  //also emit signal with progress and totalSteps together (this is better for the status message)
89  void dataProgressAndSteps( int progress, int totalSteps );
90 
91  private:
92 
93  enum ParseMode
94  {
95  none,
96  boundingBox,
97  feature, // feature element containing attrs and geo (inside gml:featureMember)
98  attribute,
99  geometry,
100  coordinate,
101  posList,
102  multiPoint,
103  multiLine,
104  multiPolygon
105  };
106 
108  void startElement( const XML_Char* el, const XML_Char** attr );
109  void endElement( const XML_Char* el );
110  void characters( const XML_Char* chars, int len );
111  static void start( void* data, const XML_Char* el, const XML_Char** attr )
112  {
113  static_cast<QgsGml*>( data )->startElement( el, attr );
114  }
115  static void end( void* data, const XML_Char* el )
116  {
117  static_cast<QgsGml*>( data )->endElement( el );
118  }
119  static void chars( void* data, const XML_Char* chars, int len )
120  {
121  static_cast<QgsGml*>( data )->characters( chars, len );
122  }
123 
124  // Set current feature attribute
125  void setAttribute( const QString& name, const QString& value );
126 
127  //helper routines
128 
134  int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const;
140  QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
143  int createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const;
149  int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const;
150 
157  int pointsFromPosListString( QList<QgsPoint>& points, const QString& coordString, int dimension ) const;
158 
159  int pointsFromString( QList<QgsPoint>& points, const QString& coordString ) const;
160  int getPointWKB( unsigned char** wkb, int* size, const QgsPoint& ) const;
161  int getLineWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& lineCoordinates ) const;
162  int getRingWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& ringCoordinates ) const;
168  int createMultiLineFromFragments();
169  int createMultiPointFromFragments();
170  int createPolygonFromFragments();
171  int createMultiPolygonFromFragments();
173  int totalWKBFragmentSize() const;
174 
176  QWidget* findMainWindow() const;
182  void calculateExtentFromFeatures();
183 
185  ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); }
186 
188  ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); }
189 
190  QString mTypeName;
191  QString mUri;
192  //results are members such that handler routines are able to manipulate them
194  QgsRectangle mExtent;
196  //QMap<QgsFeatureId, QgsFeature* > &mFeatures;
197  QMap<QgsFeatureId, QgsFeature* > mFeatures;
198  //QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures;
199 
201  //QMap<QgsFeatureId, QString > &mIdMap;
202  QMap<QgsFeatureId, QString > mIdMap;
203  //QMap<QString, QMap<QgsFeatureId, QString > > mIdMap;
205  QString mGeometryAttribute;
206  //const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
207  QMap<QString, QPair<int, QgsField> > mThematicAttributes;
208  QGis::WkbType* mWkbType;
210  bool mFinished;
212  QStack<ParseMode> mParseModeStack;
214  QString mStringCash;
215  QgsFeature* mCurrentFeature;
216  QVector<QVariant> mCurrentAttributes; //attributes of current feature
217  QString mCurrentFeatureId;
218  int mFeatureCount;
220  unsigned char* mCurrentWKB;
222  int mCurrentWKBSize;
223  QgsRectangle mCurrentExtent;
228  QList< QList<unsigned char*> > mCurrentWKBFragments;
230  QList< QList<int> > mCurrentWKBFragmentSizes;
231  QString mAttributeName;
232  QgsApplication::endian_t mEndian;
234  QString mCoordinateSeparator;
236  QString mTupleSeparator;
238  int mDimension;
240  ParseMode mCoorMode;
242  int mEpsg;
243 };
244 
245 #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:172
WkbType
Used for symbology operations.
Definition: qgis.h:53
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QMap< QgsFeatureId, QString > idsMap() const
Get feature ids map.
Definition: qgsgml.h:72
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:69
Class for storing a coordinate reference system (CRS)
double size
Definition: qgssvgcache.cpp:77