QGIS API Documentation  2.99.0-Master (314842d)
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 <list>
26 #include <QVector>
27 
28 class QgsExpression;
29 class QgsGeometry;
30 class QgsPoint;
31 class QgsRectangle;
32 
33 #include "qgsgeometry.h"
34 #include "qgsexpression.h"
35 #include "qgssqlstatement.h"
36 
44 class CORE_EXPORT QgsOgcUtils
45 {
46  public:
47 
51  typedef enum
52  {
56  } GMLVersion;
57 
63  static QgsGeometry geometryFromGML( const QString &xmlString );
64 
67  static QgsGeometry geometryFromGML( const QDomNode &geometryNode );
68 
70  static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
71 
73  static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
74 
79  static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
80  GMLVersion gmlVersion,
81  const QString &srsName,
82  bool invertAxisOrientation,
83  const QString &gmlIdBase,
84  int precision = 17 );
85 
89  static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision = 17 );
90 
94  static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision = 17 );
95 
99  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
100 
105  static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc,
106  const QString &srsName,
107  bool invertAxisOrientation,
108  int precision = 17 );
109 
113  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc, int precision = 17 );
114 
119  static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc,
120  const QString &srsName,
121  bool invertAxisOrientation,
122  int precision = 17 );
123 
124 
126  static QColor colorFromOgcFill( const QDomElement &fillElement );
127 
129  static QgsExpression *expressionFromOgcFilter( const QDomElement &element );
130 
136  static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
137 
141  typedef enum
142  {
145  FILTER_FES_2_0
146  } FilterVersion;
147 
155  static QDomElement expressionToOgcFilter( const QgsExpression &exp,
156  QDomDocument &doc,
157  GMLVersion gmlVersion,
158  FilterVersion filterVersion,
159  const QString &geometryName,
160  const QString &srsName,
161  bool honourAxisOrientation,
162  bool invertAxisOrientation,
163  QString *errorMessage = nullptr );
164 
169  static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
170 
175  static QDomElement expressionToOgcExpression( const QgsExpression &exp,
176  QDomDocument &doc,
177  GMLVersion gmlVersion,
178  FilterVersion filterVersion,
179  const QString &geometryName,
180  const QString &srsName,
181  bool honourAxisOrientation,
182  bool invertAxisOrientation,
183  QString *errorMessage = nullptr );
184 
191  {
192  public:
195 
197  QString mName;
201  QString mSRSName;
202  };
203 
221  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
222  QDomDocument &doc,
223  GMLVersion gmlVersion,
224  FilterVersion filterVersion,
225  const QList<LayerProperties> &layerProperties,
226  bool honourAxisOrientation,
227  bool invertAxisOrientation,
228  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
229  QString *errorMessage = nullptr );
230 
231  private:
232 
234  static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
236  static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
238  static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
240  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
242  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
244  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
245 
250  static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
251 
258  static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
259 
260 
265  static QDomElement createGMLCoordinates( const QgsPolyline &points, QDomDocument &doc );
266 
271  static QDomElement createGMLPositions( const QgsPolyline &points, QDomDocument &doc );
272 
274  static QgsExpression::Node *nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
276  static QgsExpression::NodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
278  static QgsExpression::NodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
280  static QgsExpression::NodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
282  static QgsExpression::NodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
284  static QgsExpression::Node *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
286  static QgsExpression::NodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
288  static QgsExpression::Node *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
290  static QgsExpression::NodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
291 };
292 
298 {
299  public:
301  QgsOgcUtilsExprToFilter( QDomDocument &doc,
302  QgsOgcUtils::GMLVersion gmlVersion,
303  QgsOgcUtils::FilterVersion filterVersion,
304  const QString &geometryName,
305  const QString &srsName,
306  bool honourAxisOrientation,
307  bool invertAxisOrientation );
308 
310  QDomElement expressionNodeToOgcFilter( const QgsExpression::Node *node );
311 
313  bool GMLNamespaceUsed() const { return mGMLUsed; }
314 
316  QString errorMessage() const { return mErrorMessage; }
317 
318  private:
319  QDomDocument &mDoc;
320  bool mGMLUsed;
321  QgsOgcUtils::GMLVersion mGMLVersion;
322  QgsOgcUtils::FilterVersion mFilterVersion;
323  const QString &mGeometryName;
324  const QString &mSrsName;
325  bool mInvertAxisOrientation;
326  QString mErrorMessage;
327  QString mFilterPrefix;
328  QString mPropertyName;
329  int mGeomId;
330 
331  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpression::NodeUnaryOperator *node );
332  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpression::NodeBinaryOperator *node );
333  QDomElement expressionLiteralToOgcFilter( const QgsExpression::NodeLiteral *node );
334  QDomElement expressionColumnRefToOgcFilter( const QgsExpression::NodeColumnRef *node );
335  QDomElement expressionInOperatorToOgcFilter( const QgsExpression::NodeInOperator *node );
336  QDomElement expressionFunctionToOgcFilter( const QgsExpression::NodeFunction *node );
337 };
338 
344 {
345  public:
347  QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
348  QgsOgcUtils::GMLVersion gmlVersion,
349  QgsOgcUtils::FilterVersion filterVersion,
350  const QList<QgsOgcUtils::LayerProperties> &layerProperties,
351  bool honourAxisOrientation,
352  bool invertAxisOrientation,
353  const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
354 
356  QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
357 
359  bool GMLNamespaceUsed() const { return mGMLUsed; }
360 
362  QString errorMessage() const { return mErrorMessage; }
363 
364  private:
365  QDomDocument &mDoc;
366  bool mGMLUsed;
367  QgsOgcUtils::GMLVersion mGMLVersion;
368  QgsOgcUtils::FilterVersion mFilterVersion;
369  const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
370  bool mHonourAxisOrientation;
371  bool mInvertAxisOrientation;
372  QString mErrorMessage;
373  QString mFilterPrefix;
374  QString mPropertyName;
375  int mGeomId;
376  QString mCurrentSRSName;
377  QMap<QString, QString> mMapTableAliasToNames;
378  const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
379 
380  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
381  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
382  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
383  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
384  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
385  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
386  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
387  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
388  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
389 
390  void visit( const QgsSQLStatement::NodeTableDef *node );
391  QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
392  bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
393  QList<QgsSQLStatement::Node *> args,
394  bool lastArgIsSRSName,
395  QString &srsName,
396  bool &axisInversion );
397 };
398 
399 #endif // QGSOGCUTILS_H
Class for parsing and evaluation of expressions (formerly called "search strings").
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:297
Function with a name and arguments node.
QVector< QgsPoint > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:47
QString errorMessage() const
Return the error message.
Definition: qgsogcutils.h:316
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:359
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:79
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:190
Abstract node class.
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:313
QString mName
Layer name.
Definition: qgsogcutils.h:197
Class for parsing SQL statements.
Literal value (integer, integer64, double, string)
QString errorMessage() const
Return the error message.
Definition: qgsogcutils.h:362
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:343
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:201
A class to represent a point.
Definition: qgspoint.h:37
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:141
Reference to a column.
&#39;X BETWEEN y and z&#39; operator
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:199
GMLVersion
GML version.
Definition: qgsogcutils.h:51
LayerProperties()
Constructor.
Definition: qgsogcutils.h:194
&#39;x IN (y, z)&#39; operator
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:44