QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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:
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 geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
316
321 static QDomElement filterElement(
322 QDomDocument &doc,
323 QgsOgcUtils::GMLVersion gmlVersion,
324 FilterVersion filterVersion,
325 bool GMLUsed );
326
333 static bool readGMLCoordinates( QgsPolylineXY &coords, const QDomElement &elem );
334
343 static bool readGMLPositions( QgsPolylineXY &coords, const QDomElement &elem );
344
345
352 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
353
360 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
361
363 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
365 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
367 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
369 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
371 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
373 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
375 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
377 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
379 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
380};
381
382#ifndef SIP_RUN
383
390{
391 public:
393 QgsOgcUtilsExprToFilter( QDomDocument &doc,
394 QgsOgcUtils::GMLVersion gmlVersion,
395 QgsOgcUtils::FilterVersion filterVersion,
396 const QString &namespacePrefix,
397 const QString &namespaceURI,
398 const QString &geometryName,
399 const QString &srsName,
400 bool honourAxisOrientation,
401 bool invertAxisOrientation,
402 const QMap<QString, QString> &fieldNameToXPathMap,
403 const QMap<QString, QString> &namespacePrefixToUriMap
404 );
405
407 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
408
410 bool GMLNamespaceUsed() const { return mGMLUsed; }
411
413 QString errorMessage() const { return mErrorMessage; }
414
415 private:
416 QDomDocument &mDoc;
417 bool mGMLUsed;
418 QgsOgcUtils::GMLVersion mGMLVersion;
419 QgsOgcUtils::FilterVersion mFilterVersion;
420 const QString &mNamespacePrefix;
421 const QString &mNamespaceURI;
422 const QString &mGeometryName;
423 const QString &mSrsName;
424 bool mInvertAxisOrientation;
425 const QMap<QString, QString> &mFieldNameToXPathMap;
426 const QMap<QString, QString> &mNamespacePrefixToUriMap;
427 QString mErrorMessage;
428 QString mFilterPrefix;
429 QString mPropertyName;
430 int mGeomId;
431
432 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
433 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
434 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
435 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
436 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
437 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
438};
439
447{
448 public:
449
456 const QgsVectorLayer *layer = nullptr );
457
463 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
464
469 QString errorMessage() const;
470
476 QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( const QDomElement &element );
477
482 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
483
488 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
489
494 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
495
500 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
501
506 QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( const QDomElement &element );
507
512 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
513
518 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
519
520 private:
521 const QgsVectorLayer *mLayer = nullptr;
522 QString mErrorMessage;
523 QString mPropertyName;
524 QString mPrefix;
525};
526
533{
534 public:
536 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
537 QgsOgcUtils::GMLVersion gmlVersion,
538 QgsOgcUtils::FilterVersion filterVersion,
539 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
540 bool honourAxisOrientation,
541 bool invertAxisOrientation,
542 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
543 const QMap<QString, QString> &fieldNameToXPathMap,
544 const QMap<QString, QString> &namespacePrefixToUriMap );
545
547 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
548
550 bool GMLNamespaceUsed() const { return mGMLUsed; }
551
553 QString errorMessage() const { return mErrorMessage; }
554
555 private:
556 QDomDocument &mDoc;
557 bool mGMLUsed;
558 QgsOgcUtils::GMLVersion mGMLVersion;
559 QgsOgcUtils::FilterVersion mFilterVersion;
560 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
561 bool mHonourAxisOrientation;
562 bool mInvertAxisOrientation;
563 QString mErrorMessage;
564 QString mFilterPrefix;
565 QString mPropertyName;
566 int mGeomId;
567 QString mCurrentSRSName;
568 QMap<QString, QString> mMapTableAliasToNames;
569 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
570 const QMap<QString, QString> &mFieldNameToXPathMap;
571 const QMap<QString, QString> &mNamespacePrefixToUriMap;
572
573 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
574 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
575 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
576 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
577 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
578 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
579 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
580 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
581 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
582
583 void visit( const QgsSQLStatement::NodeTableDef *node );
584 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
585 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
586 QList<QgsSQLStatement::Node *> args,
587 bool lastArgIsSRSName,
588 QString &srsName,
589 bool &axisInversion );
590};
591
598class CORE_EXPORT QgsOgcCrsUtils
599{
600 public:
601
603 enum class CRSFlavor
604 {
605 UNKNOWN,
606 AUTH_CODE,
607 HTTP_EPSG_DOT_XML,
608 OGC_URN,
609 X_OGC_URN,
610 OGC_HTTP_URI,
611 };
612
622 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
623};
624
626
627#endif // #ifndef SIP_RUN
628
629#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:76
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.
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