QGIS API Documentation 3.31.0-Master (d8a37248f1)
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;
34
35#include "qgsgeometry.h"
36#include "qgsexpression.h"
37#include "qgsexpressionnode.h"
39#include "qgssqlstatement.h"
41
51class CORE_EXPORT QgsOgcUtils
52{
53 public:
54
59 struct Context
60 {
61
65 Context( const QgsMapLayer *layer = nullptr, const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext() )
66 : layer( layer )
67 , transformContext( transformContext )
68 {
69 }
70 const QgsMapLayer *layer = nullptr;
72 };
73
78 {
82 };
83
91 static QgsGeometry geometryFromGML( const QString &xmlString, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
92
96 static QgsGeometry geometryFromGML( const QDomNode &geometryNode, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
97
99 static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
100
102 static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
103
109 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
110 QgsOgcUtils::GMLVersion gmlVersion,
111 const QString &srsName,
112 bool invertAxisOrientation,
113 const QString &gmlIdBase,
114 int precision = 17 );
115
120 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
121
126 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
127
132 static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
133
139 static QDomElement rectangleToGMLBox( QgsRectangle *box, QDomDocument &doc,
140 const QString &srsName,
141 bool invertAxisOrientation,
142 int precision = 17 );
143
148 static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc, int precision = 17 );
149
155 static QDomElement rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument &doc,
156 const QString &srsName,
157 bool invertAxisOrientation,
158 int precision = 17 );
159
160
162 static QColor colorFromOgcFill( const QDomElement &fillElement );
163
165 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
166
173 static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
174
179 {
182 FILTER_FES_2_0
183 };
184
192 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
193
202 static QDomElement expressionToOgcFilter( const QgsExpression &exp,
203 QDomDocument &doc,
204 QgsOgcUtils::GMLVersion gmlVersion,
205 FilterVersion filterVersion,
206 const QString &namespacePrefix,
207 const QString &namespaceURI,
208 const QString &geometryName,
209 const QString &srsName,
210 bool honourAxisOrientation,
211 bool invertAxisOrientation,
212 QString *errorMessage = nullptr ) SIP_SKIP;
213
220 static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr,
221 bool requiresFilterElement = false );
222
228 static QDomElement elseFilterExpression( QDomDocument &doc );
229
235 static QDomElement expressionToOgcExpression( const QgsExpression &exp,
236 QDomDocument &doc,
237 QgsOgcUtils::GMLVersion gmlVersion,
238 FilterVersion filterVersion,
239 const QString &geometryName,
240 const QString &srsName,
241 bool honourAxisOrientation,
242 bool invertAxisOrientation,
243 QString *errorMessage = nullptr,
244 bool requiresFilterElement = false );
245
246#ifndef SIP_RUN
247
255 {
256 public:
258 LayerProperties() = default;
259
261 QString mName;
265 QString mSRSName;
270 };
271#endif
272
291 static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
292 QDomDocument &doc,
293 QgsOgcUtils::GMLVersion gmlVersion,
294 FilterVersion filterVersion,
295 const QList<LayerProperties> &layerProperties,
296 bool honourAxisOrientation,
297 bool invertAxisOrientation,
298 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
299 QString *errorMessage = nullptr ) SIP_SKIP;
300
301 private:
302
304 static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
306 static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
308 static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
310 static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
312 static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
314 static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
315
320 static QDomElement filterElement(
321 QDomDocument &doc,
322 QgsOgcUtils::GMLVersion gmlVersion,
323 FilterVersion filterVersion,
324 bool GMLUsed );
325
332 static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
333
342 static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
343
344
351 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
352
359 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
360
362 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
364 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
366 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
368 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
370 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
372 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
374 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
376 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
378 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
379};
380
381#ifndef SIP_RUN
382
389{
390 public:
392 QgsOgcUtilsExprToFilter( QDomDocument &doc,
393 QgsOgcUtils::GMLVersion gmlVersion,
394 QgsOgcUtils::FilterVersion filterVersion,
395 const QString &namespacePrefix,
396 const QString &namespaceURI,
397 const QString &geometryName,
398 const QString &srsName,
399 bool honourAxisOrientation,
400 bool invertAxisOrientation );
401
403 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
404
406 bool GMLNamespaceUsed() const { return mGMLUsed; }
407
409 QString errorMessage() const { return mErrorMessage; }
410
411 private:
412 QDomDocument &mDoc;
413 bool mGMLUsed;
414 QgsOgcUtils::GMLVersion mGMLVersion;
415 QgsOgcUtils::FilterVersion mFilterVersion;
416 const QString &mNamespacePrefix;
417 const QString &mNamespaceURI;
418 const QString &mGeometryName;
419 const QString &mSrsName;
420 bool mInvertAxisOrientation;
421 QString mErrorMessage;
422 QString mFilterPrefix;
423 QString mPropertyName;
424 int mGeomId;
425
426 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
427 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
428 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
429 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
430 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
431 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
432};
433
441{
442 public:
443
450 const QgsVectorLayer *layer = nullptr );
451
457 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
458
463 QString errorMessage() const;
464
470 QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
471
476 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
477
482 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
483
488 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
489
494 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
495
500 QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
501
506 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
507
512 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
513
514 private:
515 const QgsVectorLayer *mLayer = nullptr;
516 QString mErrorMessage;
517 QString mPropertyName;
518 QString mPrefix;
519};
520
527{
528 public:
530 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
531 QgsOgcUtils::GMLVersion gmlVersion,
532 QgsOgcUtils::FilterVersion filterVersion,
533 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
534 bool honourAxisOrientation,
535 bool invertAxisOrientation,
536 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
537
539 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
540
542 bool GMLNamespaceUsed() const { return mGMLUsed; }
543
545 QString errorMessage() const { return mErrorMessage; }
546
547 private:
548 QDomDocument &mDoc;
549 bool mGMLUsed;
550 QgsOgcUtils::GMLVersion mGMLVersion;
551 QgsOgcUtils::FilterVersion mFilterVersion;
552 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
553 bool mHonourAxisOrientation;
554 bool mInvertAxisOrientation;
555 QString mErrorMessage;
556 QString mFilterPrefix;
557 QString mPropertyName;
558 int mGeomId;
559 QString mCurrentSRSName;
560 QMap<QString, QString> mMapTableAliasToNames;
561 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
562
563 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
564 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
565 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
566 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
567 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
568 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
569 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
570 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
571 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
572
573 void visit( const QgsSQLStatement::NodeTableDef *node );
574 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
575 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
576 QList<QgsSQLStatement::Node *> args,
577 bool lastArgIsSRSName,
578 QString &srsName,
579 bool &axisInversion );
580};
581
588class CORE_EXPORT QgsOgcCrsUtils
589{
590 public:
591
593 enum class CRSFlavor
594 {
595 UNKNOWN,
596 AUTH_CODE,
597 HTTP_EPSG_DOT_XML,
598 OGC_URN,
599 X_OGC_URN,
600 OGC_HTTP_URI,
601 };
602
612 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
613};
614
616
617#endif // #ifndef SIP_RUN
618
619#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:589
CRSFlavor
CRS flavor.
Definition: qgsogcutils.h:594
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:389
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:406
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:409
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:441
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:527
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:542
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:545
QString mSRSName
SRS name.
Definition: qgsogcutils.h:265
LayerProperties()=default
Constructor.
QString mNamespaceURI
Namespace URI.
Definition: qgsogcutils.h:269
QString mNamespacePrefix
Namespace prefix.
Definition: qgsogcutils.h:267
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:263
QString mName
Layer name.
Definition: qgsogcutils.h:261
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:52
GMLVersion
GML version.
Definition: qgsogcutils.h:78
FilterVersion
OGC filter version.
Definition: qgsogcutils.h:179
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:60
Context(const QgsMapLayer *layer=nullptr, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructs a Context from layer and transformContext.
Definition: qgsogcutils.h:65
QgsCoordinateTransformContext transformContext
Definition: qgsogcutils.h:71