QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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
18class QColor;
19class QDomNode;
20class QDomElement;
21class QDomDocument;
22class QString;
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include <list>
27#include <QVector>
28
29class QgsExpression;
30class QgsGeometry;
31class QgsPointXY;
32class QgsRectangle;
33class QgsVectorLayer;
34class QgsMapLayer;
35
36
37#include "qgsgeometry.h"
38#include "qgsexpression.h"
39#include "qgsexpressionnode.h"
41#include "qgssqlstatement.h"
43
53class CORE_EXPORT QgsOgcUtils
54{
55 public:
56
61 struct Context
62 {
63
67 Context( const QgsMapLayer *layer = nullptr, const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext() )
68 : layer( layer )
69 , transformContext( transformContext )
70 {
71 }
72 const QgsMapLayer *layer = nullptr;
74 };
75
80 {
84 };
85
93 static QgsGeometry geometryFromGML( const QString &xmlString, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
94
98 static QgsGeometry geometryFromGML( const QDomNode &geometryNode, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
99
101 static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
102
104 static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
105
111 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
112 QgsOgcUtils::GMLVersion gmlVersion,
113 const QString &srsName,
114 bool invertAxisOrientation,
115 const QString &gmlIdBase,
116 int precision = 17 );
117
122 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
123
128 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
129
134 static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
135
141 static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc,
142 const QString &srsName,
143 bool invertAxisOrientation,
144 int precision = 17 );
145
150 static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc, int precision = 17 );
151
157 static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc,
158 const QString &srsName,
159 bool invertAxisOrientation,
160 int precision = 17 );
161
162
164 static QColor colorFromOgcFill( const QDomElement &fillElement );
165
167 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
168
175 static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
176
181 {
184 FILTER_FES_2_0
185 };
186
194 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
195
204 static QDomElement expressionToOgcFilter( const QgsExpression &exp,
205 QDomDocument &doc,
206 QgsOgcUtils::GMLVersion gmlVersion,
207 FilterVersion filterVersion,
208 const QString &namespacePrefix,
209 const QString &namespaceURI,
210 const QString &geometryName,
211 const QString &srsName,
212 bool honourAxisOrientation,
213 bool invertAxisOrientation,
214 QString *errorMessage = nullptr ) SIP_SKIP;
215
222 static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr,
223 bool requiresFilterElement = false );
224
230 static QDomElement elseFilterExpression( QDomDocument &doc );
231
237 static QDomElement expressionToOgcExpression( const QgsExpression &exp,
238 QDomDocument &doc,
239 QgsOgcUtils::GMLVersion gmlVersion,
240 FilterVersion filterVersion,
241 const QString &geometryName,
242 const QString &srsName,
243 bool honourAxisOrientation,
244 bool invertAxisOrientation,
245 QString *errorMessage = nullptr,
246 bool requiresFilterElement = false );
247
248#ifndef SIP_RUN
249
257 {
258 public:
260 LayerProperties() = default;
261
263 QString mName;
267 QString mSRSName;
272 };
273#endif
274
293 static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
294 QDomDocument &doc,
295 QgsOgcUtils::GMLVersion gmlVersion,
296 FilterVersion filterVersion,
297 const QList<LayerProperties> &layerProperties,
298 bool honourAxisOrientation,
299 bool invertAxisOrientation,
300 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
301 QString *errorMessage = nullptr ) SIP_SKIP;
302
303 private:
304
306 static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
308 static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
310 static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
312 static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
314 static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
316 static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
317
322 static QDomElement filterElement(
323 QDomDocument &doc,
324 QgsOgcUtils::GMLVersion gmlVersion,
325 FilterVersion filterVersion,
326 bool GMLUsed );
327
334 static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
335
344 static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
345
346
353 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
354
361 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
362
364 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
366 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
368 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
370 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
372 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
374 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
376 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
378 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
380 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
381};
382
383#ifndef SIP_RUN
384
391{
392 public:
394 QgsOgcUtilsExprToFilter( QDomDocument &doc,
395 QgsOgcUtils::GMLVersion gmlVersion,
396 QgsOgcUtils::FilterVersion filterVersion,
397 const QString &namespacePrefix,
398 const QString &namespaceURI,
399 const QString &geometryName,
400 const QString &srsName,
401 bool honourAxisOrientation,
402 bool invertAxisOrientation );
403
405 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
406
408 bool GMLNamespaceUsed() const { return mGMLUsed; }
409
411 QString errorMessage() const { return mErrorMessage; }
412
413 private:
414 QDomDocument &mDoc;
415 bool mGMLUsed;
416 QgsOgcUtils::GMLVersion mGMLVersion;
417 QgsOgcUtils::FilterVersion mFilterVersion;
418 const QString &mNamespacePrefix;
419 const QString &mNamespaceURI;
420 const QString &mGeometryName;
421 const QString &mSrsName;
422 bool mInvertAxisOrientation;
423 QString mErrorMessage;
424 QString mFilterPrefix;
425 QString mPropertyName;
426 int mGeomId;
427
428 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
429 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
430 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
431 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
432 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
433 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
434};
435
443{
444 public:
445
452 const QgsVectorLayer *layer = nullptr );
453
459 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
460
465 QString errorMessage() const;
466
472 QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
473
478 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
479
484 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
485
490 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
491
496 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
497
502 QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
503
508 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
509
514 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
515
516 private:
517 const QgsVectorLayer *mLayer = nullptr;
518 QString mErrorMessage;
519 QString mPropertyName;
520 QString mPrefix;
521};
522
529{
530 public:
532 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
533 QgsOgcUtils::GMLVersion gmlVersion,
534 QgsOgcUtils::FilterVersion filterVersion,
535 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
536 bool honourAxisOrientation,
537 bool invertAxisOrientation,
538 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
539
541 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
542
544 bool GMLNamespaceUsed() const { return mGMLUsed; }
545
547 QString errorMessage() const { return mErrorMessage; }
548
549 private:
550 QDomDocument &mDoc;
551 bool mGMLUsed;
552 QgsOgcUtils::GMLVersion mGMLVersion;
553 QgsOgcUtils::FilterVersion mFilterVersion;
554 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
555 bool mHonourAxisOrientation;
556 bool mInvertAxisOrientation;
557 QString mErrorMessage;
558 QString mFilterPrefix;
559 QString mPropertyName;
560 int mGeomId;
561 QString mCurrentSRSName;
562 QMap<QString, QString> mMapTableAliasToNames;
563 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
564
565 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
566 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
567 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
568 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
569 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
570 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
571 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
572 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
573 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
574
575 void visit( const QgsSQLStatement::NodeTableDef *node );
576 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
577 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
578 QList<QgsSQLStatement::Node *> args,
579 bool lastArgIsSRSName,
580 QString &srsName,
581 bool &axisInversion );
582};
583
590class CORE_EXPORT QgsOgcCrsUtils
591{
592 public:
593
595 enum class CRSFlavor
596 {
597 UNKNOWN,
598 AUTH_CODE,
599 HTTP_EPSG_DOT_XML,
600 OGC_URN,
601 X_OGC_URN,
602 OGC_HTTP_URI,
603 };
604
614 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
615};
616
618
619#endif // #ifndef SIP_RUN
620
621#endif // QGSOGCUTILS_H
Contains information about the context in which a coordinate transform is executed.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A binary expression operator, which operates on two values.
An expression node which takes it value from a feature's field.
An expression node for expression functions.
An expression node for value IN or NOT IN clauses.
An expression node for literal values.
A unary node is either negative as in boolean (not) or as in numbers (minus).
Abstract base class for all nodes that can appear in an expression.
Class for parsing and evaluation of expressions (formerly called "search strings").
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Base class for all map layer types.
Definition: qgsmaplayer.h:73
Utilities related to OGC CRS encodings.
Definition: qgsogcutils.h:591
CRSFlavor
CRS flavor.
Definition: qgsogcutils.h:596
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:391
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:408
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:411
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:443
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:529
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:544
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:547
QString mSRSName
SRS name.
Definition: qgsogcutils.h:267
LayerProperties()=default
Constructor.
QString mNamespaceURI
Namespace URI.
Definition: qgsogcutils.h:271
QString mNamespacePrefix
Namespace prefix.
Definition: qgsogcutils.h:269
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:265
QString mName
Layer name.
Definition: qgsogcutils.h:263
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:54
GMLVersion
GML version.
Definition: qgsogcutils.h:80
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:181
A class to represent a 2D point.
Definition: qgspointxy.h:59
A rectangle specified with double values.
Definition: qgsrectangle.h:42
'X BETWEEN y and z' operator
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Reference to a column.
Function with a name and arguments node.
Literal value (integer, integer64, double, string)
Unary logicial/arithmetical operator ( NOT, - )
Abstract node class.
Class for parsing SQL statements.
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_FACTORY
Definition: qgis_sip.h:76
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:63
const QString & srsName
const QString & geometryName
int precision
The Context struct stores the current layer and coordinate transform context.
Definition: qgsogcutils.h:62
Context(const QgsMapLayer *layer=nullptr, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructs a Context from layer and transformContext.
Definition: qgsogcutils.h:67
QgsCoordinateTransformContext transformContext
Definition: qgsogcutils.h:73