QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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"
21 #include "qgsdataprovider.h"
22 #include "qgsfeature.h"
23 #include "qgsfield.h"
24 #include "qgslogger.h"
25 #include "qgspoint.h"
26 #include "qgsrectangle.h"
27 
28 #include <QPair>
29 #include <QByteArray>
30 #include <QDomElement>
31 #include <QStringList>
32 #include <QStack>
33 
34 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 
58  int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
59 
61  int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
62 
64  QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; }
65 
67  QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; }
68 
69  private slots:
70 
71  void setFinished();
72 
74  void handleProgressEvent( qint64 progress, qint64 totalSteps );
75 
76  signals:
77  void dataReadProgress( int progress );
78  void totalStepsUpdate( int totalSteps );
79  //also emit signal with progress and totalSteps together (this is better for the status message)
80  void dataProgressAndSteps( int progress, int totalSteps );
81 
82  private:
83 
84  enum ParseMode
85  {
88  feature, // feature element containing attrs and geo (inside gml:featureMember)
94  multiPolygon
95  };
96 
98  void startElement( const XML_Char* el, const XML_Char** attr );
99  void endElement( const XML_Char* el );
100  void characters( const XML_Char* chars, int len );
101  static void start( void* data, const XML_Char* el, const XML_Char** attr )
102  {
103  static_cast<QgsGml*>( data )->startElement( el, attr );
104  }
105  static void end( void* data, const XML_Char* el )
106  {
107  static_cast<QgsGml*>( data )->endElement( el );
108  }
109  static void chars( void* data, const XML_Char* chars, int len )
110  {
111  static_cast<QgsGml*>( data )->characters( chars, len );
112  }
113 
114  //helper routines
115 
121  int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const;
127  QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
130  int createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const;
136  int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const;
137 
138  int getPointWKB( unsigned char** wkb, int* size, const QgsPoint& ) const;
139  int getLineWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& lineCoordinates ) const;
140  int getRingWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& ringCoordinates ) const;
146  int createMultiLineFromFragments();
147  int createMultiPointFromFragments();
148  int createPolygonFromFragments();
149  int createMultiPolygonFromFragments();
151  int totalWKBFragmentSize() const;
152 
154  QWidget* findMainWindow() const;
160  void calculateExtentFromFeatures();
161 
163  ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); }
164 
166  ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); }
167 
168  QString mTypeName;
169  QString mUri;
170  //results are members such that handler routines are able to manipulate them
174  //QMap<QgsFeatureId, QgsFeature* > &mFeatures;
175  QMap<QgsFeatureId, QgsFeature* > mFeatures;
176  //QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures;
177 
179  //QMap<QgsFeatureId, QString > &mIdMap;
180  QMap<QgsFeatureId, QString > mIdMap;
181  //QMap<QString, QMap<QgsFeatureId, QString > > mIdMap;
184  //const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
185  QMap<QString, QPair<int, QgsField> > mThematicAttributes;
188  bool mFinished;
190  QStack<ParseMode> mParseModeStack;
192  QString mStringCash;
194  QVector<QVariant> mCurrentAttributes; //attributes of current feature
198  unsigned char* mCurrentWKB;
206  QList< QList<unsigned char*> > mCurrentWKBFragments;
208  QList< QList<int> > mCurrentWKBFragmentSizes;
209  QString mAttributeName;
215 };
216 
217 #endif
QgsRectangle mCurrentExtent
Definition: qgsgml.h:201
A rectangle specified with double values.
Definition: qgsrectangle.h:35
enum QgsApplication::ENDIAN endian_t
constants for endian-ness
QString mAttributeName
Definition: qgsgml.h:209
QgsApplication::endian_t mEndian
Definition: qgsgml.h:210
QString mGeometryAttribute
Name of geometry attribute.
Definition: qgsgml.h:183
static void start(void *data, const XML_Char *el, const XML_Char **attr)
Definition: qgsgml.h:101
QgsFeature * mCurrentFeature
Definition: qgsgml.h:193
ParseMode modeStackPop()
Safely (if empty) pop from mode stack.
Definition: qgsgml.h:166
Container of fields for a vector layer.
Definition: qgsfield.h:162
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:114
QMap< QgsFeatureId, QString > idsMap() const
Get feature ids map.
Definition: qgsgml.h:67
QString mTypeName
Definition: qgsgml.h:168
QString mCurrentFeatureId
Definition: qgsgml.h:195
QString mCoordinateSeparator
Coordinate separator for coordinate strings.
Definition: qgsgml.h:212
QString mUri
Definition: qgsgml.h:169
This class reads data from a WFS server or alternatively from a GML file.
Definition: qgsgml.h:41
int mFeatureCount
Definition: qgsgml.h:196
unsigned char * mCurrentWKB
The total WKB for a feature.
Definition: qgsgml.h:198
ParseMode modeStackTop()
Get safely (if empty) top from mode stack.
Definition: qgsgml.h:163
static void chars(void *data, const XML_Char *chars, int len)
Definition: qgsgml.h:109
QString mTupleSeparator
Tuple separator for coordinate strings.
Definition: qgsgml.h:214
QVector< QVariant > mCurrentAttributes
Definition: qgsgml.h:194
A class to represent a point geometry.
Definition: qgspoint.h:63
QGis::WkbType * mWkbType
Definition: qgsgml.h:186
static void end(void *data, const XML_Char *el)
Definition: qgsgml.h:105
QStack< ParseMode > mParseModeStack
Keep track about the most important nested elements.
Definition: qgsgml.h:190
QMap< QgsFeatureId, QgsFeature * > featuresMap() const
Get parsed features for given type name.
Definition: qgsgml.h:64
QMap< QgsFeatureId, QgsFeature * > mFeatures
The features of the layer, map of feature maps for each feature type.
Definition: qgsgml.h:175
Class for storing a coordinate reference system (CRS)
bool mFinished
True if the request is finished.
Definition: qgsgml.h:188
QList< QList< unsigned char * > > mCurrentWKBFragments
WKB intermediate storage during parsing.
Definition: qgsgml.h:206
QgsRectangle mExtent
Bounding box of the layer.
Definition: qgsgml.h:172
QList< QList< int > > mCurrentWKBFragmentSizes
Similar to mCurrentWKB, but only the size.
Definition: qgsgml.h:208
QMap< QString, QPair< int, QgsField > > mThematicAttributes
Definition: qgsgml.h:185
double size
Definition: qgssvgcache.cpp:75
int mCurrentWKBSize
The total WKB size for a feature.
Definition: qgsgml.h:200
QMap< QgsFeatureId, QString > mIdMap
Stores the relation between provider ids and WFS server ids.
Definition: qgsgml.h:180
QString mStringCash
This contains the character data if an important element has been encountered.
Definition: qgsgml.h:192
ParseMode
Definition: qgsgml.h:84