QGIS API Documentation  2.17.0-Master (6f7b933)
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 
170  {
171  public:
174 
181  };
182 
200  static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement& statement,
201  QDomDocument& doc,
202  GMLVersion gmlVersion,
203  FilterVersion filterVersion,
204  const QList<LayerProperties>& layerProperties,
205  bool honourAxisOrientation,
206  bool invertAxisOrientation,
207  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename,
208  QString* errorMessage = nullptr );
209 
210  private:
211 
213  static QgsGeometry* geometryFromGMLPoint( const QDomElement& geometryElement );
215  static QgsGeometry* geometryFromGMLLineString( const QDomElement& geometryElement );
217  static QgsGeometry* geometryFromGMLPolygon( const QDomElement& geometryElement );
219  static QgsGeometry* geometryFromGMLMultiPoint( const QDomElement& geometryElement );
221  static QgsGeometry* geometryFromGMLMultiLineString( const QDomElement& geometryElement );
223  static QgsGeometry* geometryFromGMLMultiPolygon( const QDomElement& geometryElement );
228  static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
235  static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
236 
237 
242  static QDomElement createGMLCoordinates( const QgsPolyline &points, QDomDocument& doc );
243 
248  static QDomElement createGMLPositions( const QgsPolyline &points, QDomDocument& doc );
249 
251  static QgsExpression::Node* nodeFromOgcFilter( QDomElement &element, QString &errorMessage );
253  static QgsExpression::NodeBinaryOperator* nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
255  static QgsExpression::NodeFunction* nodeSpatialOperatorFromOgcFilter( QDomElement& element, QString& errorMessage );
257  static QgsExpression::NodeUnaryOperator* nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
259  static QgsExpression::NodeFunction* nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
261  static QgsExpression::Node* nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage );
263  static QgsExpression::NodeColumnRef* nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
265  static QgsExpression::Node* nodeIsBetweenFromOgcFilter( QDomElement& element, QString& errorMessage );
267  static QgsExpression::NodeBinaryOperator* nodePropertyIsNullFromOgcFilter( QDomElement& element, QString& errorMessage );
268 };
269 
275 {
276  public:
279  QgsOgcUtils::GMLVersion gmlVersion,
280  QgsOgcUtils::FilterVersion filterVersion,
281  const QString& geometryName,
282  const QString& srsName,
283  bool honourAxisOrientation,
284  bool invertAxisOrientation );
285 
287  QDomElement expressionNodeToOgcFilter( const QgsExpression::Node* node );
288 
290  bool GMLNamespaceUsed() const { return mGMLUsed; }
291 
293  const QString& errorMessage() const { return mErrorMessage; }
294 
295  private:
296  QDomDocument& mDoc;
297  bool mGMLUsed;
298  QgsOgcUtils::GMLVersion mGMLVersion;
299  QgsOgcUtils::FilterVersion mFilterVersion;
300  const QString& mGeometryName;
301  const QString& mSrsName;
302  bool mInvertAxisOrientation;
303  QString mErrorMessage;
304  QString mFilterPrefix;
305  QString mPropertyName;
306  int mGeomId;
307 
308  QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpression::NodeUnaryOperator* node );
309  QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpression::NodeBinaryOperator* node );
310  QDomElement expressionLiteralToOgcFilter( const QgsExpression::NodeLiteral* node );
311  QDomElement expressionColumnRefToOgcFilter( const QgsExpression::NodeColumnRef* node );
312  QDomElement expressionInOperatorToOgcFilter( const QgsExpression::NodeInOperator* node );
313  QDomElement expressionFunctionToOgcFilter( const QgsExpression::NodeFunction* node );
314 };
315 
321 {
322  public:
325  QgsOgcUtils::GMLVersion gmlVersion,
326  QgsOgcUtils::FilterVersion filterVersion,
327  const QList<QgsOgcUtils::LayerProperties>& layerProperties,
328  bool honourAxisOrientation,
329  bool invertAxisOrientation,
330  const QMap< QString, QString>& mapUnprefixedTypenameToPrefixedTypename );
331 
333  QDomElement toOgcFilter( const QgsSQLStatement::Node* node );
334 
336  bool GMLNamespaceUsed() const { return mGMLUsed; }
337 
339  const QString& errorMessage() const { return mErrorMessage; }
340 
341  private:
342  QDomDocument& mDoc;
343  bool mGMLUsed;
344  QgsOgcUtils::GMLVersion mGMLVersion;
345  QgsOgcUtils::FilterVersion mFilterVersion;
346  const QList<QgsOgcUtils::LayerProperties>& mLayerProperties;
347  bool mHonourAxisOrientation;
348  bool mInvertAxisOrientation;
349  QString mErrorMessage;
350  QString mFilterPrefix;
351  QString mPropertyName;
352  int mGeomId;
353  QString mCurrentSRSName;
354  QMap<QString, QString> mMapTableAliasToNames;
355  const QMap< QString, QString>& mMapUnprefixedTypenameToPrefixedTypename;
356 
357  QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator* node );
358  QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator* node );
359  QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral* node );
360  QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef* node );
361  QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator* node );
362  QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator* node );
363  QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction* node );
364  QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin* node, const QString& leftTable );
365  QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect* node );
366 
367  void visit( const QgsSQLStatement::NodeTableDef* node );
368  QString getGeometryColumnSRSName( const QgsSQLStatement::Node* node );
369  bool processSRSName( const QgsSQLStatement::NodeFunction* mainNode,
371  bool lastArgIsSRSName,
372  QString& srsName,
373  bool& axisInversion );
374 };
375 
376 #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:274
Function with a name and arguments node.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Layer properties.
Definition: qgsogcutils.h:169
bool GMLNamespaceUsed() const
Return whether the gml: namespace is used.
Definition: qgsogcutils.h:336
Abstract node class.
QString mName
Layer name.
Definition: qgsogcutils.h:176
Class for parsing SQL statements.
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:293
const QString & errorMessage() const
Return the error message.
Definition: qgsogcutils.h:339
Literal value (integer, integer64, double, string)
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:320
Unary logicial/arithmetical operator ( NOT, - )
QString mSRSName
SRS name.
Definition: qgsogcutils.h:180
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
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:178
GMLVersion
GML version.
Definition: qgsogcutils.h:50
LayerProperties()
Constructor.
Definition: qgsogcutils.h:173
&#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:290