QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 <list>
27 #include <QVector>
28 
29 class QgsExpression;
30 class QgsGeometry;
31 class QgsPointXY;
32 class QgsRectangle;
33 class QgsVectorLayer;
34 
35 #include "qgsgeometry.h"
36 #include "qgsexpression.h"
37 #include "qgsexpressionnode.h"
38 #include "qgsexpressionnodeimpl.h"
39 #include "qgssqlstatement.h"
40 
49 class CORE_EXPORT QgsOgcUtils
50 {
51  public:
52 
57  {
61  };
62 
69  static QgsGeometry geometryFromGML( const QString &xmlString );
70 
74  static QgsGeometry geometryFromGML( const QDomNode &geometryNode );
75 
77  static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
78 
80  static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
81 
87  static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
88  QgsOgcUtils::GMLVersion gmlVersion,
89  const QString &srsName,
90  bool invertAxisOrientation,
91  const QString &gmlIdBase,
92  int precision = 17 );
93 
98  static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
99 
104  static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
105 
110  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
111 
117  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc,
118  const QString &srsName,
119  bool invertAxisOrientation,
120  int precision = 17 );
121 
126  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc, int precision = 17 );
127 
133  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc,
134  const QString &srsName,
135  bool invertAxisOrientation,
136  int precision = 17 );
137 
138 
140  static QColor colorFromOgcFill( const QDomElement &fillElement );
141 
143  static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
144 
151  static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
152 
157  {
160  FILTER_FES_2_0
161  };
162 
170  static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
171 
180  static QDomElement expressionToOgcFilter( const QgsExpression &exp,
181  QDomDocument &doc,
182  QgsOgcUtils::GMLVersion gmlVersion,
183  FilterVersion filterVersion,
184  const QString &geometryName,
185  const QString &srsName,
186  bool honourAxisOrientation,
187  bool invertAxisOrientation,
188  QString *errorMessage = nullptr ) SIP_SKIP;
189 
195  static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
196 
202  static QDomElement expressionToOgcExpression( const QgsExpression &exp,
203  QDomDocument &doc,
204  QgsOgcUtils::GMLVersion gmlVersion,
205  FilterVersion filterVersion,
206  const QString &geometryName,
207  const QString &srsName,
208  bool honourAxisOrientation,
209  bool invertAxisOrientation,
210  QString *errorMessage = nullptr );
211 
212 #ifndef SIP_RUN
213 
221  {
222  public:
224  LayerProperties() = default;
225 
227  QString mName;
231  QString mSRSName;
232  };
233 #endif
234 
253  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
254  QDomDocument &doc,
255  QgsOgcUtils::GMLVersion gmlVersion,
256  FilterVersion filterVersion,
257  const QList<LayerProperties> &layerProperties,
258  bool honourAxisOrientation,
259  bool invertAxisOrientation,
260  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
261  QString *errorMessage = nullptr ) SIP_SKIP;
262 
263  private:
264 
266  static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
268  static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
270  static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
272  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
274  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
276  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
277 
283  static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
284 
292  static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
293 
294 
300  static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
301 
307  static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
308 
310  static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
312  static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
314  static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
316  static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
318  static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
320  static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
322  static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
324  static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
326  static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
327 };
328 
329 #ifndef SIP_RUN
330 
337 {
338  public:
340  QgsOgcUtilsExprToFilter( QDomDocument &doc,
341  QgsOgcUtils::GMLVersion gmlVersion,
342  QgsOgcUtils::FilterVersion filterVersion,
343  const QString &geometryName,
344  const QString &srsName,
345  bool honourAxisOrientation,
346  bool invertAxisOrientation );
347 
349  QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
350 
352  bool GMLNamespaceUsed() const { return mGMLUsed; }
353 
355  QString errorMessage() const { return mErrorMessage; }
356 
357  private:
358  QDomDocument &mDoc;
359  bool mGMLUsed;
360  QgsOgcUtils::GMLVersion mGMLVersion;
361  QgsOgcUtils::FilterVersion mFilterVersion;
362  const QString &mGeometryName;
363  const QString &mSrsName;
364  bool mInvertAxisOrientation;
365  QString mErrorMessage;
366  QString mFilterPrefix;
367  QString mPropertyName;
368  int mGeomId;
369 
370  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
371  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
372  QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
373  QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
374  QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
375  QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
376 };
377 
385 {
386  public:
387 
394  const QgsVectorLayer *layer = nullptr );
395 
401  QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
402 
407  QString errorMessage() const;
408 
414  QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
415 
420  QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
421 
426  QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
427 
432  QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
433 
438  QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
439 
444  QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
445 
450  QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
451 
456  QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
457 
458  private:
459  const QgsVectorLayer *mLayer = nullptr;
460  QString mErrorMessage;
461  QString mPropertyName;
462  QString mPrefix;
463 };
464 
471 {
472  public:
474  QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
475  QgsOgcUtils::GMLVersion gmlVersion,
476  QgsOgcUtils::FilterVersion filterVersion,
477  const QList<QgsOgcUtils::LayerProperties> &layerProperties,
478  bool honourAxisOrientation,
479  bool invertAxisOrientation,
480  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
481 
483  QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
484 
486  bool GMLNamespaceUsed() const { return mGMLUsed; }
487 
489  QString errorMessage() const { return mErrorMessage; }
490 
491  private:
492  QDomDocument &mDoc;
493  bool mGMLUsed;
494  QgsOgcUtils::GMLVersion mGMLVersion;
495  QgsOgcUtils::FilterVersion mFilterVersion;
496  const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
497  bool mHonourAxisOrientation;
498  bool mInvertAxisOrientation;
499  QString mErrorMessage;
500  QString mFilterPrefix;
501  QString mPropertyName;
502  int mGeomId;
503  QString mCurrentSRSName;
504  QMap<QString, QString> mMapTableAliasToNames;
505  const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
506 
507  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
508  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
509  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
510  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
511  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
512  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
513  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
514  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
515  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
516 
517  void visit( const QgsSQLStatement::NodeTableDef *node );
518  QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
519  bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
520  QList<QgsSQLStatement::Node *> args,
521  bool lastArgIsSRSName,
522  QString &srsName,
523  bool &axisInversion );
524 };
525 #endif // #ifndef SIP_RUN
526 
527 #endif // QGSOGCUTILS_H
Class for parsing and evaluation of expressions (formerly called "search strings").
int precision
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:336
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:355
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:486
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:220
Abstract node class.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:352
QString mName
Layer name.
Definition: qgsogcutils.h:227
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:384
Class for parsing SQL statements.
const QString & geometryName
#define SIP_SKIP
Definition: qgis_sip.h:119
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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:489
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:470
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:231
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:156
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:49
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:229
GMLVersion
GML version.
Definition: qgsogcutils.h:56
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:49