QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 class QgsVectorLayer;
35 
36 #include "qgsgeometry.h"
37 #include "qgsexpression.h"
38 #include "qgsexpressionnode.h"
39 #include "qgsexpressionnodeimpl.h"
40 #include "qgssqlstatement.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 
171  static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
172 
181  static QDomElement expressionToOgcFilter( const QgsExpression &exp,
182  QDomDocument &doc,
183  QgsOgcUtils::GMLVersion gmlVersion,
184  FilterVersion filterVersion,
185  const QString &geometryName,
186  const QString &srsName,
187  bool honourAxisOrientation,
188  bool invertAxisOrientation,
189  QString *errorMessage = nullptr ) SIP_SKIP;
190 
196  static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
197 
203  static QDomElement expressionToOgcExpression( const QgsExpression &exp,
204  QDomDocument &doc,
205  QgsOgcUtils::GMLVersion gmlVersion,
206  FilterVersion filterVersion,
207  const QString &geometryName,
208  const QString &srsName,
209  bool honourAxisOrientation,
210  bool invertAxisOrientation,
211  QString *errorMessage = nullptr );
212 
213 #ifndef SIP_RUN
214 
222  {
223  public:
225  LayerProperties() = default;
226 
228  QString mName;
232  QString mSRSName;
233  };
234 #endif
235 
254  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
255  QDomDocument &doc,
256  QgsOgcUtils::GMLVersion gmlVersion,
257  FilterVersion filterVersion,
258  const QList<LayerProperties> &layerProperties,
259  bool honourAxisOrientation,
260  bool invertAxisOrientation,
261  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
262  QString *errorMessage = nullptr ) SIP_SKIP;
263 
264  private:
265 
267  static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
269  static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
271  static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
273  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
275  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
277  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
278 
284  static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
285 
293  static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
294 
295 
301  static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
302 
308  static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
309 
311  static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
313  static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
315  static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
317  static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
319  static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
321  static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
323  static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
325  static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
327  static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
328 };
329 
330 #ifndef SIP_RUN
331 
338 {
339  public:
341  QgsOgcUtilsExprToFilter( QDomDocument &doc,
342  QgsOgcUtils::GMLVersion gmlVersion,
343  QgsOgcUtils::FilterVersion filterVersion,
344  const QString &geometryName,
345  const QString &srsName,
346  bool honourAxisOrientation,
347  bool invertAxisOrientation );
348 
350  QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
351 
353  bool GMLNamespaceUsed() const { return mGMLUsed; }
354 
356  QString errorMessage() const { return mErrorMessage; }
357 
358  private:
359  QDomDocument &mDoc;
360  bool mGMLUsed;
361  QgsOgcUtils::GMLVersion mGMLVersion;
362  QgsOgcUtils::FilterVersion mFilterVersion;
363  const QString &mGeometryName;
364  const QString &mSrsName;
365  bool mInvertAxisOrientation;
366  QString mErrorMessage;
367  QString mFilterPrefix;
368  QString mPropertyName;
369  int mGeomId;
370 
371  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
372  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
373  QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
374  QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
375  QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
376  QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
377 };
378 
386 {
387  public:
388 
395  const QgsVectorLayer *layer = nullptr );
396 
402  QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
403 
408  QString errorMessage() const;
409 
415  QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
416 
421  QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
422 
427  QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
428 
433  QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
434 
439  QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
440 
445  QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
446 
451  QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
452 
457  QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
458 
459  private:
460  const QgsVectorLayer *mLayer = nullptr;
461  QString mErrorMessage;
462  QString mPropertyName;
463  QString mPrefix;
464 };
465 
472 {
473  public:
475  QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
476  QgsOgcUtils::GMLVersion gmlVersion,
477  QgsOgcUtils::FilterVersion filterVersion,
478  const QList<QgsOgcUtils::LayerProperties> &layerProperties,
479  bool honourAxisOrientation,
480  bool invertAxisOrientation,
481  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
482 
484  QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
485 
487  bool GMLNamespaceUsed() const { return mGMLUsed; }
488 
490  QString errorMessage() const { return mErrorMessage; }
491 
492  private:
493  QDomDocument &mDoc;
494  bool mGMLUsed;
495  QgsOgcUtils::GMLVersion mGMLVersion;
496  QgsOgcUtils::FilterVersion mFilterVersion;
497  const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
498  bool mHonourAxisOrientation;
499  bool mInvertAxisOrientation;
500  QString mErrorMessage;
501  QString mFilterPrefix;
502  QString mPropertyName;
503  int mGeomId;
504  QString mCurrentSRSName;
505  QMap<QString, QString> mMapTableAliasToNames;
506  const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
507 
508  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
509  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
510  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
511  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
512  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
513  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
514  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
515  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
516  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
517 
518  void visit( const QgsSQLStatement::NodeTableDef *node );
519  QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
520  bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
521  QList<QgsSQLStatement::Node *> args,
522  bool lastArgIsSRSName,
523  QString &srsName,
524  bool &axisInversion );
525 };
526 #endif // #ifndef SIP_RUN
527 
528 #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:40
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:337
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:490
Function with a name and arguments node.
A class to represent a 2D point.
Definition: qgspointxy.h:43
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:221
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:487
Abstract node class.
QString mName
Layer name.
Definition: qgsogcutils.h:228
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:385
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)
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:471
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:232
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:44
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:230
GMLVersion
GML version.
Definition: qgsogcutils.h:57
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:356
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
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:353