QGIS API Documentation  2.99.0-Master (13a3f2f)
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 QgsPoint;
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 
48 class CORE_EXPORT QgsOgcUtils
49 {
50  public:
51 
56  {
60  };
61 
67  static QgsGeometry geometryFromGML( const QString &xmlString );
68 
71  static QgsGeometry geometryFromGML( const QDomNode &geometryNode );
72 
74  static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
75 
77  static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
78 
83  static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
84  QgsOgcUtils::GMLVersion gmlVersion,
85  const QString &srsName,
86  bool invertAxisOrientation,
87  const QString &gmlIdBase,
88  int precision = 17 );
89 
93  static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision = 17 );
94 
98  static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision = 17 );
99 
103  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
104 
109  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc,
110  const QString &srsName,
111  bool invertAxisOrientation,
112  int precision = 17 );
113 
117  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc, int precision = 17 );
118 
123  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc,
124  const QString &srsName,
125  bool invertAxisOrientation,
126  int precision = 17 );
127 
128 
130  static QColor colorFromOgcFill( const QDomElement &fillElement );
131 
133  static QgsExpression *expressionFromOgcFilter( const QDomElement &element ) SIP_FACTORY;
134 
140  static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
141 
145  {
148  FILTER_FES_2_0
149  };
150 
158  static QDomElement expressionToOgcFilter( const QgsExpression &exp,
159  QDomDocument &doc,
160  QgsOgcUtils::GMLVersion gmlVersion,
161  FilterVersion filterVersion,
162  const QString &geometryName,
163  const QString &srsName,
164  bool honourAxisOrientation,
165  bool invertAxisOrientation,
166  QString *errorMessage = nullptr ) SIP_SKIP;
167 
172  static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
173 
178  static QDomElement expressionToOgcExpression( const QgsExpression &exp,
179  QDomDocument &doc,
180  QgsOgcUtils::GMLVersion gmlVersion,
181  FilterVersion filterVersion,
182  const QString &geometryName,
183  const QString &srsName,
184  bool honourAxisOrientation,
185  bool invertAxisOrientation,
186  QString *errorMessage = nullptr );
187 
188 #ifndef SIP_RUN
189 
196  {
197  public:
200 
202  QString mName;
206  QString mSRSName;
207  };
208 #endif
209 
227  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
228  QDomDocument &doc,
229  QgsOgcUtils::GMLVersion gmlVersion,
230  FilterVersion filterVersion,
231  const QList<LayerProperties> &layerProperties,
232  bool honourAxisOrientation,
233  bool invertAxisOrientation,
234  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
235  QString *errorMessage = nullptr ) SIP_SKIP;
236 
237  private:
238 
240  static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
242  static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
244  static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
246  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
248  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
250  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
251 
256  static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
257 
264  static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
265 
266 
271  static QDomElement createGMLCoordinates( const QgsPolyline &points, QDomDocument &doc );
272 
277  static QDomElement createGMLPositions( const QgsPolyline &points, QDomDocument &doc );
278 
280  static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
282  static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
284  static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
286  static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
288  static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
290  static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
292  static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
294  static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
296  static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
297 };
298 
299 #ifndef SIP_RUN
300 
306 {
307  public:
309  QgsOgcUtilsExprToFilter( QDomDocument &doc,
310  QgsOgcUtils::GMLVersion gmlVersion,
311  QgsOgcUtils::FilterVersion filterVersion,
312  const QString &geometryName,
313  const QString &srsName,
314  bool honourAxisOrientation,
315  bool invertAxisOrientation );
316 
318  QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node );
319 
321  bool GMLNamespaceUsed() const { return mGMLUsed; }
322 
324  QString errorMessage() const { return mErrorMessage; }
325 
326  private:
327  QDomDocument &mDoc;
328  bool mGMLUsed;
329  QgsOgcUtils::GMLVersion mGMLVersion;
330  QgsOgcUtils::FilterVersion mFilterVersion;
331  const QString &mGeometryName;
332  const QString &mSrsName;
333  bool mInvertAxisOrientation;
334  QString mErrorMessage;
335  QString mFilterPrefix;
336  QString mPropertyName;
337  int mGeomId;
338 
339  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node );
340  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node );
341  QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node );
342  QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node );
343  QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node );
344  QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node );
345 };
346 
352 {
353  public:
355  QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
356  QgsOgcUtils::GMLVersion gmlVersion,
357  QgsOgcUtils::FilterVersion filterVersion,
358  const QList<QgsOgcUtils::LayerProperties> &layerProperties,
359  bool honourAxisOrientation,
360  bool invertAxisOrientation,
361  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
362 
364  QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
365 
367  bool GMLNamespaceUsed() const { return mGMLUsed; }
368 
370  QString errorMessage() const { return mErrorMessage; }
371 
372  private:
373  QDomDocument &mDoc;
374  bool mGMLUsed;
375  QgsOgcUtils::GMLVersion mGMLVersion;
376  QgsOgcUtils::FilterVersion mFilterVersion;
377  const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
378  bool mHonourAxisOrientation;
379  bool mInvertAxisOrientation;
380  QString mErrorMessage;
381  QString mFilterPrefix;
382  QString mPropertyName;
383  int mGeomId;
384  QString mCurrentSRSName;
385  QMap<QString, QString> mMapTableAliasToNames;
386  const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
387 
388  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
389  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
390  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
391  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
392  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
393  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
394  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
395  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
396  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
397 
398  void visit( const QgsSQLStatement::NodeTableDef *node );
399  QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
400  bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
401  QList<QgsSQLStatement::Node *> args,
402  bool lastArgIsSRSName,
403  QString &srsName,
404  bool &axisInversion );
405 };
406 #endif // #ifndef SIP_RUN
407 
408 #endif // QGSOGCUTILS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:305
Function with a name and arguments node.
QVector< QgsPoint > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:48
QString errorMessage() const
Return the error message.
Definition: qgsogcutils.h:324
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:367
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:96
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:195
Abstract node class.
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:321
QString mName
Layer name.
Definition: qgsogcutils.h:202
Class for parsing SQL statements.
#define SIP_SKIP
Definition: qgis_sip.h:102
Literal value (integer, integer64, double, string)
QString errorMessage() const
Return the error message.
Definition: qgsogcutils.h:370
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:351
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:206
#define SIP_FACTORY
Definition: qgis_sip.h:57
A class to represent a point.
Definition: qgspoint.h:37
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:144
Reference to a column.
&#39;X BETWEEN y and z&#39; operator
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:204
GMLVersion
GML version.
Definition: qgsogcutils.h:55
LayerProperties()
Constructor.
Definition: qgsogcutils.h:199
&#39;x IN (y, z)&#39; operator
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:48