QGIS API Documentation  3.0.2-Girona (307d082)
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 
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 ) SIP_FACTORY;
144 
151  static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
152 
157  {
160  FILTER_FES_2_0
161  };
162 
171  static QDomElement expressionToOgcFilter( const QgsExpression &exp,
172  QDomDocument &doc,
173  QgsOgcUtils::GMLVersion gmlVersion,
174  FilterVersion filterVersion,
175  const QString &geometryName,
176  const QString &srsName,
177  bool honourAxisOrientation,
178  bool invertAxisOrientation,
179  QString *errorMessage = nullptr ) SIP_SKIP;
180 
186  static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
187 
193  static QDomElement expressionToOgcExpression( const QgsExpression &exp,
194  QDomDocument &doc,
195  QgsOgcUtils::GMLVersion gmlVersion,
196  FilterVersion filterVersion,
197  const QString &geometryName,
198  const QString &srsName,
199  bool honourAxisOrientation,
200  bool invertAxisOrientation,
201  QString *errorMessage = nullptr );
202 
203 #ifndef SIP_RUN
204 
212  {
213  public:
215  LayerProperties() = default;
216 
218  QString mName;
222  QString mSRSName;
223  };
224 #endif
225 
244  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
245  QDomDocument &doc,
246  QgsOgcUtils::GMLVersion gmlVersion,
247  FilterVersion filterVersion,
248  const QList<LayerProperties> &layerProperties,
249  bool honourAxisOrientation,
250  bool invertAxisOrientation,
251  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
252  QString *errorMessage = nullptr ) SIP_SKIP;
253 
254  private:
255 
257  static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
259  static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
261  static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
263  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
265  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
267  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
268 
274  static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
275 
283  static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
284 
285 
291  static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
292 
298  static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
299 
301  static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
303  static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
305  static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
307  static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
309  static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
311  static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
313  static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
315  static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
317  static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
318 };
319 
320 #ifndef SIP_RUN
321 
328 {
329  public:
331  QgsOgcUtilsExprToFilter( QDomDocument &doc,
332  QgsOgcUtils::GMLVersion gmlVersion,
333  QgsOgcUtils::FilterVersion filterVersion,
334  const QString &geometryName,
335  const QString &srsName,
336  bool honourAxisOrientation,
337  bool invertAxisOrientation );
338 
340  QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node );
341 
343  bool GMLNamespaceUsed() const { return mGMLUsed; }
344 
346  QString errorMessage() const { return mErrorMessage; }
347 
348  private:
349  QDomDocument &mDoc;
350  bool mGMLUsed;
351  QgsOgcUtils::GMLVersion mGMLVersion;
352  QgsOgcUtils::FilterVersion mFilterVersion;
353  const QString &mGeometryName;
354  const QString &mSrsName;
355  bool mInvertAxisOrientation;
356  QString mErrorMessage;
357  QString mFilterPrefix;
358  QString mPropertyName;
359  int mGeomId;
360 
361  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node );
362  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node );
363  QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node );
364  QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node );
365  QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node );
366  QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node );
367 };
368 
375 {
376  public:
378  QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
379  QgsOgcUtils::GMLVersion gmlVersion,
380  QgsOgcUtils::FilterVersion filterVersion,
381  const QList<QgsOgcUtils::LayerProperties> &layerProperties,
382  bool honourAxisOrientation,
383  bool invertAxisOrientation,
384  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
385 
387  QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
388 
390  bool GMLNamespaceUsed() const { return mGMLUsed; }
391 
393  QString errorMessage() const { return mErrorMessage; }
394 
395  private:
396  QDomDocument &mDoc;
397  bool mGMLUsed;
398  QgsOgcUtils::GMLVersion mGMLVersion;
399  QgsOgcUtils::FilterVersion mFilterVersion;
400  const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
401  bool mHonourAxisOrientation;
402  bool mInvertAxisOrientation;
403  QString mErrorMessage;
404  QString mFilterPrefix;
405  QString mPropertyName;
406  int mGeomId;
407  QString mCurrentSRSName;
408  QMap<QString, QString> mMapTableAliasToNames;
409  const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
410 
411  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
412  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
413  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
414  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
415  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
416  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
417  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
418  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
419  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
420 
421  void visit( const QgsSQLStatement::NodeTableDef *node );
422  QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
423  bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
424  QList<QgsSQLStatement::Node *> args,
425  bool lastArgIsSRSName,
426  QString &srsName,
427  bool &axisInversion );
428 };
429 #endif // #ifndef SIP_RUN
430 
431 #endif // QGSOGCUTILS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:39
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:327
Function with a name and arguments node.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QString errorMessage() const
Return the error message.
Definition: qgsogcutils.h:346
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:390
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:211
Abstract node class.
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:343
QString mName
Layer name.
Definition: qgsogcutils.h:218
Class for parsing SQL statements.
#define SIP_SKIP
Definition: qgis_sip.h:119
Literal value (integer, integer64, double, string)
QString errorMessage() const
Return the error message.
Definition: qgsogcutils.h:393
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:374
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:222
#define SIP_FACTORY
Definition: qgis_sip.h:69
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
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:220
GMLVersion
GML version.
Definition: qgsogcutils.h:56
&#39;x IN (y, z)&#39; operator
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:49