QGIS API Documentation  2.99.0-Master (c558d51)
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 
168  static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );
169 
174  static QDomElement expressionToOgcExpression( const QgsExpression& exp,
175  QDomDocument& doc,
176  GMLVersion gmlVersion,
177  FilterVersion filterVersion,
178  const QString& geometryName,
179  const QString& srsName,
180  bool honourAxisOrientation,
181  bool invertAxisOrientation,
182  QString* errorMessage = nullptr );
183 
190  {
191  public:
194 
196  QString mName;
200  QString mSRSName;
201  };
202 
220  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement& statement,
221  QDomDocument& doc,
222  GMLVersion gmlVersion,
223  FilterVersion filterVersion,
224  const QList<LayerProperties>& layerProperties,
225  bool honourAxisOrientation,
226  bool invertAxisOrientation,
227  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename,
228  QString* errorMessage = nullptr );
229 
230  private:
231 
233  static QgsGeometry geometryFromGMLPoint( const QDomElement& geometryElement );
235  static QgsGeometry geometryFromGMLLineString( const QDomElement& geometryElement );
237  static QgsGeometry geometryFromGMLPolygon( const QDomElement& geometryElement );
239  static QgsGeometry geometryFromGMLMultiPoint( const QDomElement& geometryElement );
241  static QgsGeometry geometryFromGMLMultiLineString( const QDomElement& geometryElement );
243  static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement& geometryElement );
244 
249  static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
250 
257  static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
258 
259 
264  static QDomElement createGMLCoordinates( const QgsPolyline &points, QDomDocument& doc );
265 
270  static QDomElement createGMLPositions( const QgsPolyline &points, QDomDocument& doc );
271 
273  static QgsExpression::Node* nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
275  static QgsExpression::NodeBinaryOperator* nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
277  static QgsExpression::NodeFunction* nodeSpatialOperatorFromOgcFilter( QDomElement& element, QString& errorMessage );
279  static QgsExpression::NodeUnaryOperator* nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
281  static QgsExpression::NodeFunction* nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
283  static QgsExpression::Node* nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
285  static QgsExpression::NodeColumnRef* nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
287  static QgsExpression::Node* nodeIsBetweenFromOgcFilter( QDomElement& element, QString& errorMessage );
289  static QgsExpression::NodeBinaryOperator* nodePropertyIsNullFromOgcFilter( QDomElement& element, QString& errorMessage );
290 };
291 
297 {
298  public:
300  QgsOgcUtilsExprToFilter( QDomDocument& doc,
301  QgsOgcUtils::GMLVersion gmlVersion,
302  QgsOgcUtils::FilterVersion filterVersion,
303  const QString& geometryName,
304  const QString& srsName,
305  bool honourAxisOrientation,
306  bool invertAxisOrientation );
307 
309  QDomElement expressionNodeToOgcFilter( const QgsExpression::Node* node );
310 
312  bool GMLNamespaceUsed() const { return mGMLUsed; }
313 
315  const QString& errorMessage() const { return mErrorMessage; }
316 
317  private:
318  QDomDocument& mDoc;
319  bool mGMLUsed;
320  QgsOgcUtils::GMLVersion mGMLVersion;
321  QgsOgcUtils::FilterVersion mFilterVersion;
322  const QString& mGeometryName;
323  const QString& mSrsName;
324  bool mInvertAxisOrientation;
325  QString mErrorMessage;
326  QString mFilterPrefix;
327  QString mPropertyName;
328  int mGeomId;
329 
330  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpression::NodeUnaryOperator* node );
331  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpression::NodeBinaryOperator* node );
332  QDomElement expressionLiteralToOgcFilter( const QgsExpression::NodeLiteral* node );
333  QDomElement expressionColumnRefToOgcFilter( const QgsExpression::NodeColumnRef* node );
334  QDomElement expressionInOperatorToOgcFilter( const QgsExpression::NodeInOperator* node );
335  QDomElement expressionFunctionToOgcFilter( const QgsExpression::NodeFunction* node );
336 };
337 
343 {
344  public:
346  QgsOgcUtilsSQLStatementToFilter( QDomDocument& doc,
347  QgsOgcUtils::GMLVersion gmlVersion,
348  QgsOgcUtils::FilterVersion filterVersion,
349  const QList<QgsOgcUtils::LayerProperties>& layerProperties,
350  bool honourAxisOrientation,
351  bool invertAxisOrientation,
352  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename );
353 
355  QDomElement toOgcFilter( const QgsSQLStatement::Node* node );
356 
358  bool GMLNamespaceUsed() const { return mGMLUsed; }
359 
361  const QString& errorMessage() const { return mErrorMessage; }
362 
363  private:
364  QDomDocument& mDoc;
365  bool mGMLUsed;
366  QgsOgcUtils::GMLVersion mGMLVersion;
367  QgsOgcUtils::FilterVersion mFilterVersion;
368  const QList<QgsOgcUtils::LayerProperties>& mLayerProperties;
369  bool mHonourAxisOrientation;
370  bool mInvertAxisOrientation;
371  QString mErrorMessage;
372  QString mFilterPrefix;
373  QString mPropertyName;
374  int mGeomId;
375  QString mCurrentSRSName;
376  QMap<QString, QString> mMapTableAliasToNames;
377  const QMap< QString, QString>& mMapUnprefixedTypenameToPrefixedTypename;
378 
379  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator* node );
380  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator* node );
381  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral* node );
382  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef* node );
383  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator* node );
384  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator* node );
385  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction* node );
386  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin* node, const QString& leftTable );
387  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect* node );
388 
389  void visit( const QgsSQLStatement::NodeTableDef* node );
390  QString getGeometryColumnSRSName( const QgsSQLStatement::Node* node );
391  bool processSRSName( const QgsSQLStatement::NodeFunction* mainNode,
392  QList<QgsSQLStatement::Node*> args,
393  bool lastArgIsSRSName,
394  QString& srsName,
395  bool& axisInversion );
396 };
397 
398 #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:296
Function with a name and arguments node.
QVector< QgsPoint > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:46
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:78
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:189
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:358
Abstract node class.
QString mName
Layer name.
Definition: qgsogcutils.h:196
Class for parsing SQL statements.
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:315
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:361
Literal value (integer, integer64, double, string)
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:342
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:200
A class to represent a point.
Definition: qgspoint.h:111
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:140
Reference to a column.
&#39;X BETWEEN y and z&#39; operator
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:198
GMLVersion
GML version.
Definition: qgsogcutils.h:50
LayerProperties()
Constructor.
Definition: qgsogcutils.h:193
&#39;x IN (y, z)&#39; operator
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:43
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:312