QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 expressionToOgcExpression( const QgsExpression &exp,
229 QDomDocument &doc,
230 QgsOgcUtils::GMLVersion gmlVersion,
231 FilterVersion filterVersion,
232 const QString &geometryName,
233 const QString &srsName,
234 bool honourAxisOrientation,
235 bool invertAxisOrientation,
236 QString *errorMessage = nullptr,
237 bool requiresFilterElement = false );
238
239#ifndef SIP_RUN
240
248 {
249 public:
251 LayerProperties() = default;
252
254 QString mName;
258 QString mSRSName;
263 };
264#endif
265
284 static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
285 QDomDocument &doc,
286 QgsOgcUtils::GMLVersion gmlVersion,
287 FilterVersion filterVersion,
288 const QList<LayerProperties> &layerProperties,
289 bool honourAxisOrientation,
290 bool invertAxisOrientation,
291 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
292 QString *errorMessage = nullptr ) SIP_SKIP;
293
294 private:
295
297 static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
299 static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
301 static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
303 static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
305 static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
307 static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
308
313 static QDomElement filterElement(
314 QDomDocument &doc,
315 QgsOgcUtils::GMLVersion gmlVersion,
316 FilterVersion filterVersion,
317 bool GMLUsed );
318
325 static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
326
335 static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
336
337
344 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
345
352 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
353
355 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
357 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
359 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
361 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
363 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
365 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
367 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
369 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
371 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
372};
373
374#ifndef SIP_RUN
375
382{
383 public:
385 QgsOgcUtilsExprToFilter( QDomDocument &doc,
386 QgsOgcUtils::GMLVersion gmlVersion,
387 QgsOgcUtils::FilterVersion filterVersion,
388 const QString &namespacePrefix,
389 const QString &namespaceURI,
390 const QString &geometryName,
391 const QString &srsName,
392 bool honourAxisOrientation,
393 bool invertAxisOrientation );
394
396 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
397
399 bool GMLNamespaceUsed() const { return mGMLUsed; }
400
402 QString errorMessage() const { return mErrorMessage; }
403
404 private:
405 QDomDocument &mDoc;
406 bool mGMLUsed;
407 QgsOgcUtils::GMLVersion mGMLVersion;
408 QgsOgcUtils::FilterVersion mFilterVersion;
409 const QString &mNamespacePrefix;
410 const QString &mNamespaceURI;
411 const QString &mGeometryName;
412 const QString &mSrsName;
413 bool mInvertAxisOrientation;
414 QString mErrorMessage;
415 QString mFilterPrefix;
416 QString mPropertyName;
417 int mGeomId;
418
419 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
420 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
421 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
422 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
423 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
424 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
425};
426
434{
435 public:
436
443 const QgsVectorLayer *layer = nullptr );
444
450 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
451
456 QString errorMessage() const;
457
463 QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
464
469 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
470
475 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
476
481 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
482
487 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
488
493 QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
494
499 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
500
505 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
506
507 private:
508 const QgsVectorLayer *mLayer = nullptr;
509 QString mErrorMessage;
510 QString mPropertyName;
511 QString mPrefix;
512};
513
520{
521 public:
523 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
524 QgsOgcUtils::GMLVersion gmlVersion,
525 QgsOgcUtils::FilterVersion filterVersion,
526 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
527 bool honourAxisOrientation,
528 bool invertAxisOrientation,
529 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename );
530
532 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
533
535 bool GMLNamespaceUsed() const { return mGMLUsed; }
536
538 QString errorMessage() const { return mErrorMessage; }
539
540 private:
541 QDomDocument &mDoc;
542 bool mGMLUsed;
543 QgsOgcUtils::GMLVersion mGMLVersion;
544 QgsOgcUtils::FilterVersion mFilterVersion;
545 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
546 bool mHonourAxisOrientation;
547 bool mInvertAxisOrientation;
548 QString mErrorMessage;
549 QString mFilterPrefix;
550 QString mPropertyName;
551 int mGeomId;
552 QString mCurrentSRSName;
553 QMap<QString, QString> mMapTableAliasToNames;
554 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
555
556 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
557 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
558 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
559 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
560 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
561 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
562 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
563 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
564 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
565
566 void visit( const QgsSQLStatement::NodeTableDef *node );
567 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
568 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
569 QList<QgsSQLStatement::Node *> args,
570 bool lastArgIsSRSName,
571 QString &srsName,
572 bool &axisInversion );
573};
574
581class CORE_EXPORT QgsOgcCrsUtils
582{
583 public:
584
586 enum class CRSFlavor
587 {
588 UNKNOWN,
589 AUTH_CODE,
590 HTTP_EPSG_DOT_XML,
591 OGC_URN,
592 X_OGC_URN,
593 OGC_HTTP_URI,
594 };
595
605 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
606};
607
609
610#endif // #ifndef SIP_RUN
611
612#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:582
CRSFlavor
CRS flavor.
Definition: qgsogcutils.h:587
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:382
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:399
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:402
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:434
Internal use by QgsOgcUtils.
Definition: qgsogcutils.h:520
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
Definition: qgsogcutils.h:535
QString errorMessage() const
Returns the error message.
Definition: qgsogcutils.h:538
QString mSRSName
SRS name.
Definition: qgsogcutils.h:258
LayerProperties()=default
Constructor.
QString mNamespaceURI
Namespace URI.
Definition: qgsogcutils.h:262
QString mNamespacePrefix
Namespace prefix.
Definition: qgsogcutils.h:260
QString mGeometryAttribute
Geometry attribute name.
Definition: qgsogcutils.h:256
QString mName
Layer name.
Definition: qgsogcutils.h:254
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