QGIS API Documentation  2.15.0-Master (af20121)
qgsogcutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsogcutils.h
3  ---------------------
4  begin : March 2013
5  copyright : (C) 2013 by Martin Dobias
6  email : wonder dot sk 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 QGSOGCUTILS_H
16 #define QGSOGCUTILS_H
17 
18 class QColor;
19 class QDomNode;
20 class QDomElement;
21 class QDomDocument;
22 class QString;
23 
24 #include <list>
25 #include <QVector>
26 
27 class QgsExpression;
28 class QgsGeometry;
29 class QgsPoint;
30 class QgsRectangle;
31 
32 #include "qgsgeometry.h"
33 #include "qgsexpression.h"
34 #include "qgssqlstatement.h"
35 
43 class CORE_EXPORT QgsOgcUtils
44 {
45  public:
46 
50  typedef enum
51  {
55  } GMLVersion;
56 
62  static QgsGeometry* geometryFromGML( const QString& xmlString );
63 
66  static QgsGeometry* geometryFromGML( const QDomNode& geometryNode );
67 
69  static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );
70 
72  static QgsRectangle rectangleFromGMLEnvelope( const QDomNode& envelopeNode );
73 
78  static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc,
79  GMLVersion gmlVersion,
80  const QString& srsName,
81  bool invertAxisOrientation,
82  const QString& gmlIdBase,
83  int precision = 17 );
84 
88  static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc, const QString& format, int precision = 17 );
89 
93  static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc, int precision = 17 );
94 
98  static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc, int precision = 17 );
99 
104  static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc,
105  const QString& srsName,
106  bool invertAxisOrientation,
107  int precision = 17 );
108 
112  static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc, int precision = 17 );
113 
118  static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc,
119  const QString& srsName,
120  bool invertAxisOrientation,
121  int precision = 17 );
122 
123 
125  static QColor colorFromOgcFill( const QDomElement& fillElement );
126 
128  static QgsExpression* expressionFromOgcFilter( const QDomElement& element );
129 
135  static QDomElement expressionToOgcFilter( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );
136 
140  typedef enum
141  {
144  FILTER_FES_2_0
145  } FilterVersion;
146 
154  static QDomElement expressionToOgcFilter( const QgsExpression& exp,
155  QDomDocument& doc,
156  GMLVersion gmlVersion,
157  FilterVersion filterVersion,
158  const QString& geometryName,
159  const QString& srsName,
160  bool honourAxisOrientation,
161  bool invertAxisOrientation,
162  QString* errorMessage = nullptr );
163 
169  {
170  public:
173 
180  };
181 
199  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement& statement,
200  QDomDocument& doc,
201  GMLVersion gmlVersion,
202  FilterVersion filterVersion,
203  const QList<LayerProperties>& layerProperties,
204  bool honourAxisOrientation,
205  bool invertAxisOrientation,
206  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename,
207  QString* errorMessage = nullptr );
208 
209  private:
210 
212  static QgsGeometry* geometryFromGMLPoint( const QDomElement& geometryElement );
214  static QgsGeometry* geometryFromGMLLineString( const QDomElement& geometryElement );
216  static QgsGeometry* geometryFromGMLPolygon( const QDomElement& geometryElement );
218  static QgsGeometry* geometryFromGMLMultiPoint( const QDomElement& geometryElement );
220  static QgsGeometry* geometryFromGMLMultiLineString( const QDomElement& geometryElement );
222  static QgsGeometry* geometryFromGMLMultiPolygon( const QDomElement& geometryElement );
227  static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
234  static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
235 
236 
241  static QDomElement createGMLCoordinates( const QgsPolyline &points, QDomDocument& doc );
242 
247  static QDomElement createGMLPositions( const QgsPolyline &points, QDomDocument& doc );
248 
250  static QgsExpression::Node* nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
252  static QgsExpression::NodeBinaryOperator* nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
254  static QgsExpression::NodeFunction* nodeSpatialOperatorFromOgcFilter( QDomElement& element, QString& errorMessage );
256  static QgsExpression::NodeUnaryOperator* nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
258  static QgsExpression::NodeFunction* nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
260  static QgsExpression::Node* nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
262  static QgsExpression::NodeColumnRef* nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
264  static QgsExpression::Node* nodeIsBetweenFromOgcFilter( QDomElement& element, QString& errorMessage );
266  static QgsExpression::NodeBinaryOperator* nodePropertyIsNullFromOgcFilter( QDomElement& element, QString& errorMessage );
267 };
268 
273 {
274  public:
277  QgsOgcUtils::GMLVersion gmlVersion,
278  QgsOgcUtils::FilterVersion filterVersion,
279  const QString& geometryName,
280  const QString& srsName,
281  bool honourAxisOrientation,
282  bool invertAxisOrientation );
283 
285  QDomElement expressionNodeToOgcFilter( const QgsExpression::Node* node );
286 
288  bool GMLNamespaceUsed() const { return mGMLUsed; }
289 
291  const QString& errorMessage() const { return mErrorMessage; }
292 
293  private:
294  QDomDocument& mDoc;
295  bool mGMLUsed;
296  QgsOgcUtils::GMLVersion mGMLVersion;
297  QgsOgcUtils::FilterVersion mFilterVersion;
298  const QString& mGeometryName;
299  const QString& mSrsName;
300  bool mInvertAxisOrientation;
301  QString mErrorMessage;
302  QString mFilterPrefix;
303  QString mPropertyName;
304  int mGeomId;
305 
306  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpression::NodeUnaryOperator* node );
307  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpression::NodeBinaryOperator* node );
308  QDomElement expressionLiteralToOgcFilter( const QgsExpression::NodeLiteral* node );
309  QDomElement expressionColumnRefToOgcFilter( const QgsExpression::NodeColumnRef* node );
310  QDomElement expressionInOperatorToOgcFilter( const QgsExpression::NodeInOperator* node );
311  QDomElement expressionFunctionToOgcFilter( const QgsExpression::NodeFunction* node );
312 };
313 
318 {
319  public:
322  QgsOgcUtils::GMLVersion gmlVersion,
323  QgsOgcUtils::FilterVersion filterVersion,
324  const QList<QgsOgcUtils::LayerProperties>& layerProperties,
325  bool honourAxisOrientation,
326  bool invertAxisOrientation,
327  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename );
328 
330  QDomElement toOgcFilter( const QgsSQLStatement::Node* node );
331 
333  bool GMLNamespaceUsed() const { return mGMLUsed; }
334 
336  const QString& errorMessage() const { return mErrorMessage; }
337 
338  private:
339  QDomDocument& mDoc;
340  bool mGMLUsed;
341  QgsOgcUtils::GMLVersion mGMLVersion;
342  QgsOgcUtils::FilterVersion mFilterVersion;
343  const QList<QgsOgcUtils::LayerProperties>& mLayerProperties;
344  bool mHonourAxisOrientation;
345  bool mInvertAxisOrientation;
346  QString mErrorMessage;
347  QString mFilterPrefix;
348  QString mPropertyName;
349  int mGeomId;
350  QString mCurrentSRSName;
351  QMap<QString, QString> mMapTableAliasToNames;
352  const QMap< QString, QString>& mMapUnprefixedTypenameToPrefixedTypename;
353 
354  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator* node );
355  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator* node );
356  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral* node );
357  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef* node );
358  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator* node );
359  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator* node );
360  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction* node );
361  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin* node, const QString& leftTable );
362  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect* node );
363 
364  void visit( const QgsSQLStatement::NodeTableDef* node );
365  QString getGeometryColumnSRSName( const QgsSQLStatement::Node* node );
366  bool processSRSName( const QgsSQLStatement::NodeFunction* mainNode,
368  bool lastArgIsSRSName,
369  QString& srsName,
370  bool& axisInversion );
371 };
372 
373 #endif // QGSOGCUTILS_H
Class for parsing and evaluation of expressions (formerly called "search strings").
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:272
Function with a name and arguments node.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:168
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:333
Abstract node class.
QString mName
Layer name.
Definition: qgsogcutils.h:175
Class for parsing SQL statements.
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:291
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:336
Literal value (integer, integer64, double, string)
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:317
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:179
A class to represent a point.
Definition: qgspoint.h:117
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:140
Reference to a column.
&#39;X BETWEEN y and z&#39; operator
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:177
GMLVersion
GML version.
Definition: qgsogcutils.h:50
LayerProperties()
Constructor.
Definition: qgsogcutils.h:172
&#39;x IN (y, z)&#39; operator
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:43
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:288