QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 <list>
25 #include <QVector>
26 
27 class QgsExpression;
28 class QgsGeometry;
29 class QgsPoint;
30 class QgsRectangle;
31 
32 #include "qgsgeometry.h"
33 #include "qgsexpression.h"
34 #include "qgssqlstatement.h"
35 
43 class CORE_EXPORT QgsOgcUtils
44 {
45  public:
46 
50  typedef enum
51  {
55  } GMLVersion;
56 
62  static QgsGeometry* geometryFromGML( const QString& xmlString );
63 
66  static QgsGeometry* geometryFromGML( const QDomNode& geometryNode );
67 
69  static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );
70 
72  static QgsRectangle rectangleFromGMLEnvelope( const QDomNode& envelopeNode );
73 
78  static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc,
79  GMLVersion gmlVersion,
80  const QString& srsName,
81  bool invertAxisOrientation,
82  const QString& gmlIdBase,
83  int precision = 17 );
84 
88  static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc, const QString& format, int precision = 17 );
89 
93  static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc, int precision = 17 );
94 
98  static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc, int precision = 17 );
99 
104  static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc,
105  const QString& srsName,
106  bool invertAxisOrientation,
107  int precision = 17 );
108 
112  static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc, int precision = 17 );
113 
118  static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc,
119  const QString& srsName,
120  bool invertAxisOrientation,
121  int precision = 17 );
122 
123 
125  static QColor colorFromOgcFill( const QDomElement& fillElement );
126 
128  static QgsExpression* expressionFromOgcFilter( const QDomElement& element );
129 
135  static QDomElement expressionToOgcFilter( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );
136 
140  typedef enum
141  {
144  FILTER_FES_2_0
145  } FilterVersion;
146 
154  static QDomElement expressionToOgcFilter( const QgsExpression& exp,
155  QDomDocument& doc,
156  GMLVersion gmlVersion,
157  FilterVersion filterVersion,
158  const QString& geometryName,
159  const QString& srsName,
160  bool honourAxisOrientation,
161  bool invertAxisOrientation,
162  QString* errorMessage = nullptr );
163 
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 
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 );
249  static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
256  static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
257 
258 
263  static QDomElement createGMLCoordinates( const QgsPolyline &points, QDomDocument& doc );
264 
269  static QDomElement createGMLPositions( const QgsPolyline &points, QDomDocument& doc );
270 
272  static QgsExpression::Node* nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
274  static QgsExpression::NodeBinaryOperator* nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
276  static QgsExpression::NodeFunction* nodeSpatialOperatorFromOgcFilter( QDomElement& element, QString& errorMessage );
278  static QgsExpression::NodeUnaryOperator* nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
280  static QgsExpression::NodeFunction* nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
282  static QgsExpression::Node* nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
284  static QgsExpression::NodeColumnRef* nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
286  static QgsExpression::Node* nodeIsBetweenFromOgcFilter( QDomElement& element, QString& errorMessage );
288  static QgsExpression::NodeBinaryOperator* nodePropertyIsNullFromOgcFilter( QDomElement& element, QString& errorMessage );
289 };
290 
296 {
297  public:
300  QgsOgcUtils::GMLVersion gmlVersion,
301  QgsOgcUtils::FilterVersion filterVersion,
302  const QString& geometryName,
303  const QString& srsName,
304  bool honourAxisOrientation,
305  bool invertAxisOrientation );
306 
308  QDomElement expressionNodeToOgcFilter( const QgsExpression::Node* node );
309 
311  bool GMLNamespaceUsed() const { return mGMLUsed; }
312 
314  const QString& errorMessage() const { return mErrorMessage; }
315 
316  private:
317  QDomDocument& mDoc;
318  bool mGMLUsed;
319  QgsOgcUtils::GMLVersion mGMLVersion;
320  QgsOgcUtils::FilterVersion mFilterVersion;
321  const QString& mGeometryName;
322  const QString& mSrsName;
323  bool mInvertAxisOrientation;
324  QString mErrorMessage;
325  QString mFilterPrefix;
326  QString mPropertyName;
327  int mGeomId;
328 
329  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpression::NodeUnaryOperator* node );
330  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpression::NodeBinaryOperator* node );
331  QDomElement expressionLiteralToOgcFilter( const QgsExpression::NodeLiteral* node );
332  QDomElement expressionColumnRefToOgcFilter( const QgsExpression::NodeColumnRef* node );
333  QDomElement expressionInOperatorToOgcFilter( const QgsExpression::NodeInOperator* node );
334  QDomElement expressionFunctionToOgcFilter( const QgsExpression::NodeFunction* node );
335 };
336 
342 {
343  public:
346  QgsOgcUtils::GMLVersion gmlVersion,
347  QgsOgcUtils::FilterVersion filterVersion,
348  const QList<QgsOgcUtils::LayerProperties>& layerProperties,
349  bool honourAxisOrientation,
350  bool invertAxisOrientation,
351  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename );
352 
354  QDomElement toOgcFilter( const QgsSQLStatement::Node* node );
355 
357  bool GMLNamespaceUsed() const { return mGMLUsed; }
358 
360  const QString& errorMessage() const { return mErrorMessage; }
361 
362  private:
363  QDomDocument& mDoc;
364  bool mGMLUsed;
365  QgsOgcUtils::GMLVersion mGMLVersion;
366  QgsOgcUtils::FilterVersion mFilterVersion;
367  const QList<QgsOgcUtils::LayerProperties>& mLayerProperties;
368  bool mHonourAxisOrientation;
369  bool mInvertAxisOrientation;
370  QString mErrorMessage;
371  QString mFilterPrefix;
372  QString mPropertyName;
373  int mGeomId;
374  QString mCurrentSRSName;
375  QMap<QString, QString> mMapTableAliasToNames;
376  const QMap< QString, QString>& mMapUnprefixedTypenameToPrefixedTypename;
377 
378  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator* node );
379  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator* node );
380  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral* node );
381  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef* node );
382  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator* node );
383  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator* node );
384  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction* node );
385  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin* node, const QString& leftTable );
386  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect* node );
387 
388  void visit( const QgsSQLStatement::NodeTableDef* node );
389  QString getGeometryColumnSRSName( const QgsSQLStatement::Node* node );
390  bool processSRSName( const QgsSQLStatement::NodeFunction* mainNode,
392  bool lastArgIsSRSName,
393  QString& srsName,
394  bool& axisInversion );
395 };
396 
397 #endif // QGSOGCUTILS_H
Class for parsing and evaluation of expressions (formerly called "search strings").
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:295
Function with a name and arguments node.
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:360
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:357
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
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:311
QString mName
Layer name.
Definition: qgsogcutils.h:197
Class for parsing SQL statements.
Literal value (integer, integer64, double, string)
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:341
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:201
A class to represent a point.
Definition: qgspoint.h:117
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:140
Reference to a column.
&#39;X BETWEEN y and z&#39; operator
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:314
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:199
GMLVersion
GML version.
Definition: qgsogcutils.h:50
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:43