QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgis_core.h"
25 #include "qgis_sip.h"
26 #include "qgis.h"
27 #include <list>
28 #include <QVector>
29 
30 class QgsExpression;
31 class QgsGeometry;
32 class QgsPointXY;
33 class QgsRectangle;
34 
35 #include "qgsgeometry.h"
36 #include "qgsexpression.h"
37 #include "qgsexpressionnode.h"
38 #include "qgsexpressionnodeimpl.h"
39 #include "qgssqlstatement.h"
40 #include "qgsvectorlayer.h"
41 
50 class CORE_EXPORT QgsOgcUtils
51 {
52  public:
53 
58  {
62  };
63 
70  static QgsGeometry geometryFromGML( const QString &xmlString );
71 
75  static QgsGeometry geometryFromGML( const QDomNode &geometryNode );
76 
78  static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
79 
81  static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
82 
88  static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
89  QgsOgcUtils::GMLVersion gmlVersion,
90  const QString &srsName,
91  bool invertAxisOrientation,
92  const QString &gmlIdBase,
93  int precision = 17 );
94 
99  static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
100 
105  static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
106 
111  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
112 
118  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc,
119  const QString &srsName,
120  bool invertAxisOrientation,
121  int precision = 17 );
122 
127  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc, int precision = 17 );
128 
134  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc,
135  const QString &srsName,
136  bool invertAxisOrientation,
137  int precision = 17 );
138 
139 
141  static QColor colorFromOgcFill( const QDomElement &fillElement );
142 
144  static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
145 
152  static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
153 
158  {
161  FILTER_FES_2_0
162  };
163 
172  static QDomElement expressionToOgcFilter( const QgsExpression &exp,
173  QDomDocument &doc,
174  QgsOgcUtils::GMLVersion gmlVersion,
175  FilterVersion filterVersion,
176  const QString &geometryName,
177  const QString &srsName,
178  bool honourAxisOrientation,
179  bool invertAxisOrientation,
180  QString *errorMessage = nullptr ) SIP_SKIP;
181 
187  static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
188 
194  static QDomElement expressionToOgcExpression( const QgsExpression &exp,
195  QDomDocument &doc,
196  QgsOgcUtils::GMLVersion gmlVersion,
197  FilterVersion filterVersion,
198  const QString &geometryName,
199  const QString &srsName,
200  bool honourAxisOrientation,
201  bool invertAxisOrientation,
202  QString *errorMessage = nullptr );
203 
204 #ifndef SIP_RUN
205 
213  {
214  public:
216  LayerProperties() = default;
217 
219  QString mName;
223  QString mSRSName;
224  };
225 #endif
226 
245  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
246  QDomDocument &doc,
247  QgsOgcUtils::GMLVersion gmlVersion,
248  FilterVersion filterVersion,
249  const QList<LayerProperties> &layerProperties,
250  bool honourAxisOrientation,
251  bool invertAxisOrientation,
252  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
253  QString *errorMessage = nullptr ) SIP_SKIP;
254 
255  private:
256 
258  static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
260  static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
262  static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
264  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
266  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
268  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
269 
275  static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
276 
284  static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
285 
286 
292  static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
293 
299  static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
300 
302  static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
304  static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
306  static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
308  static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
310  static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
312  static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
314  static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
316  static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
318  static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
319 };
320 
321 #ifndef SIP_RUN
322 
329 {
330  public:
332  QgsOgcUtilsExprToFilter( QDomDocument &doc,
333  QgsOgcUtils::GMLVersion gmlVersion,
334  QgsOgcUtils::FilterVersion filterVersion,
335  const QString &geometryName,
336  const QString &srsName,
337  bool honourAxisOrientation,
338  bool invertAxisOrientation );
339 
341  QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node );
342 
344  bool GMLNamespaceUsed() const { return mGMLUsed; }
345 
347  QString errorMessage() const { return mErrorMessage; }
348 
349  private:
350  QDomDocument &mDoc;
351  bool mGMLUsed;
352  QgsOgcUtils::GMLVersion mGMLVersion;
353  QgsOgcUtils::FilterVersion mFilterVersion;
354  const QString &mGeometryName;
355  const QString &mSrsName;
356  bool mInvertAxisOrientation;
357  QString mErrorMessage;
358  QString mFilterPrefix;
359  QString mPropertyName;
360  int mGeomId;
361 
362  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node );
363  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node );
364  QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node );
365  QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node );
366  QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node );
367  QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node );
368 };
369 
376 {
377  public:
379  QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
380  QgsOgcUtils::GMLVersion gmlVersion,
381  QgsOgcUtils::FilterVersion filterVersion,
382  const QList<QgsOgcUtils::LayerProperties> &layerProperties,
383  bool honourAxisOrientation,
384  bool invertAxisOrientation,
385  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
386 
388  QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
389 
391  bool GMLNamespaceUsed() const { return mGMLUsed; }
392 
394  QString errorMessage() const { return mErrorMessage; }
395 
396  private:
397  QDomDocument &mDoc;
398  bool mGMLUsed;
399  QgsOgcUtils::GMLVersion mGMLVersion;
400  QgsOgcUtils::FilterVersion mFilterVersion;
401  const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
402  bool mHonourAxisOrientation;
403  bool mInvertAxisOrientation;
404  QString mErrorMessage;
405  QString mFilterPrefix;
406  QString mPropertyName;
407  int mGeomId;
408  QString mCurrentSRSName;
409  QMap<QString, QString> mMapTableAliasToNames;
410  const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
411 
412  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
413  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
414  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
415  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
416  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
417  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
418  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
419  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
420  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
421 
422  void visit( const QgsSQLStatement::NodeTableDef *node );
423  QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
424  bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
425  QList<QgsSQLStatement::Node *> args,
426  bool lastArgIsSRSName,
427  QString &srsName,
428  bool &axisInversion );
429 };
430 #endif // #ifndef SIP_RUN
431 
432 #endif // QGSOGCUTILS_H
Class for parsing and evaluation of expressions (formerly called "search strings").
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:328
Function with a name and arguments node.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:347
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:391
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:104
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:212
Abstract node class.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:344
QString mName
Layer name.
Definition: qgsogcutils.h:219
Class for parsing SQL statements.
#define SIP_SKIP
Definition: qgis_sip.h:119
An expression node for value IN or NOT IN clauses.
Literal value (integer, integer64, double, string)
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:394
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:375
An expression node which takes it value from a feature&#39;s field.
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:223
Abstract base class for all nodes that can appear in an expression.
#define SIP_FACTORY
Definition: qgis_sip.h:69
An expression node for expression functions.
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:157
Reference to a column.
&#39;X BETWEEN y and z&#39; operator
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:42
An expression node for literal values.
A unary node is either negative as in boolean (not) or as in numbers (minus).
A binary expression operator, which operates on two values.
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:221
GMLVersion
GML version.
Definition: qgsogcutils.h:57
Represents a vector layer which manages a vector based data sets.
&#39;x IN (y, z)&#39; operator
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:50