QGIS API Documentation 3.99.0-Master (9e5f463f1a9)
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
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
110 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
111 QgsOgcUtils::GMLVersion gmlVersion,
112 const QString &srsName,
113 bool invertAxisOrientation,
114 const QString &gmlIdBase,
115 int precision = 17 );
116
121 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
122
127 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
128
133 static QDomElement rectangleToGMLBox( const QgsRectangle *box, QDomDocument &doc, int precision = 17 );
134
139 static QDomElement rectangleToGMLBox( const QgsRectangle *box, QDomDocument &doc,
140 const QString &srsName,
141 bool invertAxisOrientation,
142 int precision = 17 );
143
148 static QDomElement rectangleToGMLEnvelope( const QgsRectangle *env, QDomDocument &doc, int precision = 17 );
149
154 static QDomElement rectangleToGMLEnvelope( const QgsRectangle *env, QDomDocument &doc,
155 const QString &srsName,
156 bool invertAxisOrientation,
157 int precision = 17 );
158
159
161 static QColor colorFromOgcFill( const QDomElement &fillElement );
162
164 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
165
172 static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
173
178 {
181 FILTER_FES_2_0
182 };
183
191 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
192
200 static QDomElement expressionToOgcFilter( const QgsExpression &exp,
201 QDomDocument &doc,
202 QgsOgcUtils::GMLVersion gmlVersion,
203 FilterVersion filterVersion,
204 const QString &namespacePrefix,
205 const QString &namespaceURI,
206 const QString &geometryName,
207 const QString &srsName,
208 bool honourAxisOrientation,
209 bool invertAxisOrientation,
210 QString *errorMessage = nullptr,
211 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
212 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() ) 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 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
246 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() );
247
248#ifndef SIP_RUN
249
256 {
257 public:
258 LayerProperties() = default;
259
261 QString mName;
265 QString mSRSName;
270 };
271#endif
272
290 static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
291 QDomDocument &doc,
292 QgsOgcUtils::GMLVersion gmlVersion,
293 FilterVersion filterVersion,
294 const QList<LayerProperties> &layerProperties,
295 bool honourAxisOrientation,
296 bool invertAxisOrientation,
297 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
298 QString *errorMessage = nullptr,
299 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
300 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() ) SIP_SKIP;
301
302 private:
303
305 static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
307 static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
309 static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
311 static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
313 static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
315 static QgsGeometry geometryFromGMLMultiCurve( const QDomElement &geometryElement );
317 static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
319 static QgsGeometry geometryFromGMLUsingGdal( const QDomElement &geometryElement );
320
325 static QDomElement filterElement(
326 QDomDocument &doc,
327 QgsOgcUtils::GMLVersion gmlVersion,
328 FilterVersion filterVersion,
329 bool GMLUsed );
330
337 static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
338
347 static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
348
355 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
356
363 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
364
366 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
368 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
370 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
372 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
374 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
376 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
378 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
380 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
382 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
383};
384
385
386
387#ifndef SIP_RUN
388
395{
396 public:
398 QgsOgcUtilsExprToFilter( QDomDocument &doc,
399 QgsOgcUtils::GMLVersion gmlVersion,
400 QgsOgcUtils::FilterVersion filterVersion,
401 const QString &namespacePrefix,
402 const QString &namespaceURI,
403 const QString &geometryName,
404 const QString &srsName,
405 bool honourAxisOrientation,
406 bool invertAxisOrientation,
407 const QMap<QString, QString> &fieldNameToXPathMap,
408 const QMap<QString, QString> &namespacePrefixToUriMap
409 );
410
412 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
413
415 bool GMLNamespaceUsed() const { return mGMLUsed; }
416
418 QString errorMessage() const { return mErrorMessage; }
419
420 private:
421 QDomDocument &mDoc;
422 bool mGMLUsed;
423 QgsOgcUtils::GMLVersion mGMLVersion;
424 QgsOgcUtils::FilterVersion mFilterVersion;
425 QString mNamespacePrefix;
426 QString mNamespaceURI;
427 QString mGeometryName;
428 QString mSrsName;
429 bool mInvertAxisOrientation;
430 QMap<QString, QString> mFieldNameToXPathMap;
431 QMap<QString, QString> mNamespacePrefixToUriMap;
432 QString mErrorMessage;
433 QString mFilterPrefix;
434 QString mPropertyName;
435 int mGeomId;
436
437 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
438 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
439 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
440 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
441 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
442 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
443};
444
452{
453 public:
454
461 const QgsVectorLayer *layer = nullptr );
462
468 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
469
474 QString errorMessage() const;
475
481 QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
482
487 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
488
493 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
494
499 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
500
505 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
506
511 QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
512
517 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
518
523 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
524
525 private:
526 const QgsVectorLayer *mLayer = nullptr;
527 QString mErrorMessage;
528 QString mPropertyName;
529 QString mPrefix;
530};
531
538{
539 public:
541 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
542 QgsOgcUtils::GMLVersion gmlVersion,
543 QgsOgcUtils::FilterVersion filterVersion,
544 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
545 bool honourAxisOrientation,
546 bool invertAxisOrientation,
547 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
548 const QMap<QString, QString> &fieldNameToXPathMap,
549 const QMap<QString, QString> &namespacePrefixToUriMap );
550
552 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
553
555 bool GMLNamespaceUsed() const { return mGMLUsed; }
556
558 QString errorMessage() const { return mErrorMessage; }
559
560 private:
561 QDomDocument &mDoc;
562 bool mGMLUsed;
563 QgsOgcUtils::GMLVersion mGMLVersion;
564 QgsOgcUtils::FilterVersion mFilterVersion;
565 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
566 bool mHonourAxisOrientation;
567 bool mInvertAxisOrientation;
568 QString mErrorMessage;
569 QString mFilterPrefix;
570 QString mPropertyName;
571 int mGeomId;
572 QString mCurrentSRSName;
573 QMap<QString, QString> mMapTableAliasToNames;
574 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
575 const QMap<QString, QString> &mFieldNameToXPathMap;
576 const QMap<QString, QString> &mNamespacePrefixToUriMap;
577
578 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
579 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
580 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
581 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
582 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
583 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
584 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
585 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
586 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
587
588 void visit( const QgsSQLStatement::NodeTableDef *node );
589 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
590 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
591 QList<QgsSQLStatement::Node *> args,
592 bool lastArgIsSRSName,
593 QString &srsName,
594 bool &axisInversion );
595};
596
603class CORE_EXPORT QgsOgcCrsUtils
604{
605 public:
606
608 enum class CRSFlavor
609 {
610 UNKNOWN,
611 AUTH_CODE,
612 HTTP_EPSG_DOT_XML,
613 OGC_URN,
614 X_OGC_URN,
615 OGC_HTTP_URI,
616 };
617
627 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
628};
629
631
632#endif // #ifndef SIP_RUN
633
634#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 its 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.
Handles parsing and evaluation of expressions (formerly called "search strings").
A geometry is the spatial representation of a feature.
Base class for all map layer types.
Definition qgsmaplayer.h:78
Utilities related to OGC CRS encodings.
CRSFlavor
CRS flavor.
Internal use by QgsOgcUtils.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
QString errorMessage() const
Returns the error message.
Internal use by QgsOgcUtils.
Internal use by QgsOgcUtils.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
QString errorMessage() const
Returns the error message.
QString mNamespaceURI
Namespace URI.
QString mNamespacePrefix
Namespace prefix.
QString mGeometryAttribute
Geometry attribute name.
QString mName
Layer name.
Provides various utility functions for conversion between OGC (Open Geospatial Consortium) standards ...
Definition qgsogcutils.h:54
GMLVersion
GML version.
Definition qgsogcutils.h:80
FilterVersion
OGC filter version.
Represents a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
An 'X BETWEEN y and z' operator.
Binary logical/arithmetical operator (AND, OR, =, +, ...).
Function with a name and arguments node.
An 'x IN (y, z)' operator.
Literal value (integer, integer64, double, string).
Unary logical/arithmetical operator ( NOT, - ).
Abstract node class for SQL statement nodes.
Parses SQL statements.
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:62
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition qgsgeometry.h:71
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