QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
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( QgsRectangle *box, QDomDocument &doc, int precision = 17 );
134
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
154 static QDomElement rectangleToGMLEnvelope( 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:
259 LayerProperties() = default;
260
262 QString mName;
266 QString mSRSName;
271 };
272#endif
273
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,
300 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
301 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() ) 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 const QMap<QString, QString> &fieldNameToXPathMap,
404 const QMap<QString, QString> &namespacePrefixToUriMap
405 );
406
408 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
409
411 bool GMLNamespaceUsed() const { return mGMLUsed; }
412
414 QString errorMessage() const { return mErrorMessage; }
415
416 private:
417 QDomDocument &mDoc;
418 bool mGMLUsed;
419 QgsOgcUtils::GMLVersion mGMLVersion;
420 QgsOgcUtils::FilterVersion mFilterVersion;
421 const QString &mNamespacePrefix;
422 const QString &mNamespaceURI;
423 const QString &mGeometryName;
424 const QString &mSrsName;
425 bool mInvertAxisOrientation;
426 const QMap<QString, QString> &mFieldNameToXPathMap;
427 const QMap<QString, QString> &mNamespacePrefixToUriMap;
428 QString mErrorMessage;
429 QString mFilterPrefix;
430 QString mPropertyName;
431 int mGeomId;
432
433 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
434 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
435 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
436 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
437 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
438 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
439};
440
448{
449 public:
450
457 const QgsVectorLayer *layer = nullptr );
458
464 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
465
470 QString errorMessage() const;
471
477 QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
478
483 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
484
489 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
490
495 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
496
501 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
502
507 QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
508
513 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
514
519 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
520
521 private:
522 const QgsVectorLayer *mLayer = nullptr;
523 QString mErrorMessage;
524 QString mPropertyName;
525 QString mPrefix;
526};
527
534{
535 public:
537 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
538 QgsOgcUtils::GMLVersion gmlVersion,
539 QgsOgcUtils::FilterVersion filterVersion,
540 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
541 bool honourAxisOrientation,
542 bool invertAxisOrientation,
543 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
544 const QMap<QString, QString> &fieldNameToXPathMap,
545 const QMap<QString, QString> &namespacePrefixToUriMap );
546
548 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
549
551 bool GMLNamespaceUsed() const { return mGMLUsed; }
552
554 QString errorMessage() const { return mErrorMessage; }
555
556 private:
557 QDomDocument &mDoc;
558 bool mGMLUsed;
559 QgsOgcUtils::GMLVersion mGMLVersion;
560 QgsOgcUtils::FilterVersion mFilterVersion;
561 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
562 bool mHonourAxisOrientation;
563 bool mInvertAxisOrientation;
564 QString mErrorMessage;
565 QString mFilterPrefix;
566 QString mPropertyName;
567 int mGeomId;
568 QString mCurrentSRSName;
569 QMap<QString, QString> mMapTableAliasToNames;
570 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
571 const QMap<QString, QString> &mFieldNameToXPathMap;
572 const QMap<QString, QString> &mNamespacePrefixToUriMap;
573
574 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
575 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
576 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
577 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
578 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
579 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
580 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
581 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
582 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
583
584 void visit( const QgsSQLStatement::NodeTableDef *node );
585 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
586 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
587 QList<QgsSQLStatement::Node *> args,
588 bool lastArgIsSRSName,
589 QString &srsName,
590 bool &axisInversion );
591};
592
599class CORE_EXPORT QgsOgcCrsUtils
600{
601 public:
602
604 enum class CRSFlavor
605 {
606 UNKNOWN,
607 AUTH_CODE,
608 HTTP_EPSG_DOT_XML,
609 OGC_URN,
610 X_OGC_URN,
611 OGC_HTTP_URI,
612 };
613
623 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
624};
625
627
628#endif // #ifndef SIP_RUN
629
630#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.
Base class for all map layer types.
Definition qgsmaplayer.h:75
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.
LayerProperties()=default
Constructor.
QString mNamespaceURI
Namespace URI.
QString mNamespacePrefix
Namespace prefix.
QString mGeometryAttribute
Geometry attribute name.
QString mName
Layer name.
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.
A class to represent a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
'X BETWEEN y and z' operator
Binary logical/arithmetical operator (AND, OR, =, +, ...)
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:62
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