QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <list>
25
26#include "qgis_core.h"
27#include "qgis_sip.h"
28
29#include <QVector>
30
31class QgsExpression;
32class QgsGeometry;
33class QgsPointXY;
34class QgsRectangle;
35class QgsVectorLayer;
36class QgsMapLayer;
37
38
39#include "qgsgeometry.h"
40#include "qgsexpression.h"
41#include "qgsexpressionnode.h"
43#include "qgssqlstatement.h"
45
55class CORE_EXPORT QgsOgcUtils
56{
57 public:
58
77
87
95 static QgsGeometry geometryFromGML( const QString &xmlString, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
96
100 static QgsGeometry geometryFromGML( const QDomNode &geometryNode, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
101
103 static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
104
106 static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
107
112 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
113 QgsOgcUtils::GMLVersion gmlVersion,
114 const QString &srsName,
115 bool invertAxisOrientation,
116 const QString &gmlIdBase,
117 int precision = 17 );
118
123 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
124
129 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
130
135 static QDomElement rectangleToGMLBox( const QgsRectangle *box, QDomDocument &doc, int precision = 17 );
136
141 static QDomElement rectangleToGMLBox( const QgsRectangle *box, QDomDocument &doc,
142 const QString &srsName,
143 bool invertAxisOrientation,
144 int precision = 17 );
145
150 static QDomElement rectangleToGMLEnvelope( const QgsRectangle *env, QDomDocument &doc, int precision = 17 );
151
156 static QDomElement rectangleToGMLEnvelope( const QgsRectangle *env, QDomDocument &doc,
157 const QString &srsName,
158 bool invertAxisOrientation,
159 int precision = 17 );
160
161
163 static QColor colorFromOgcFill( const QDomElement &fillElement );
164
166 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
167
174 static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
175
185
193 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
194
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,
213 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
214 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() ) SIP_SKIP;
215
222 static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr,
223 bool requiresFilterElement = false );
224
230 static QDomElement elseFilterExpression( QDomDocument &doc );
231
237 static QDomElement expressionToOgcExpression( const QgsExpression &exp,
238 QDomDocument &doc,
239 QgsOgcUtils::GMLVersion gmlVersion,
240 FilterVersion filterVersion,
241 const QString &geometryName,
242 const QString &srsName,
243 bool honourAxisOrientation,
244 bool invertAxisOrientation,
245 QString *errorMessage = nullptr,
246 bool requiresFilterElement = false,
247 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
248 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() );
249
250#ifndef SIP_RUN
251
258 {
259 public:
260 LayerProperties() = default;
261
263 QString mName;
267 QString mSRSName;
272 };
273#endif
274
292 static QDomElement SQLStatementToOgcFilter( const QgsSQLStatement &statement,
293 QDomDocument &doc,
294 QgsOgcUtils::GMLVersion gmlVersion,
295 FilterVersion filterVersion,
296 const QList<LayerProperties> &layerProperties,
297 bool honourAxisOrientation,
298 bool invertAxisOrientation,
299 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
300 QString *errorMessage = nullptr,
301 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
302 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>() ) SIP_SKIP;
303
304 private:
305
307 static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
309 static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
311 static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
313 static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
315 static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
317 static QgsGeometry geometryFromGMLMultiCurve( const QDomElement &geometryElement );
319 static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
321 static QgsGeometry geometryFromGMLUsingGdal( const QDomElement &geometryElement );
322
327 static QDomElement filterElement(
328 QDomDocument &doc,
329 QgsOgcUtils::GMLVersion gmlVersion,
330 FilterVersion filterVersion,
331 bool GMLUsed );
332
339 static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
340
349 static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
350
357 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
358
365 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
366
368 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
370 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
372 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
374 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
376 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
378 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
380 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
382 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
384 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
385};
386
387
388
389#ifndef SIP_RUN
390
397{
398 public:
400 QgsOgcUtilsExprToFilter( QDomDocument &doc,
401 QgsOgcUtils::GMLVersion gmlVersion,
402 QgsOgcUtils::FilterVersion filterVersion,
403 const QString &namespacePrefix,
404 const QString &namespaceURI,
405 const QString &geometryName,
406 const QString &srsName,
407 bool honourAxisOrientation,
408 bool invertAxisOrientation,
409 const QMap<QString, QString> &fieldNameToXPathMap,
410 const QMap<QString, QString> &namespacePrefixToUriMap
411 );
412
414 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
415
417 bool GMLNamespaceUsed() const { return mGMLUsed; }
418
420 QString errorMessage() const { return mErrorMessage; }
421
422 private:
423 QDomDocument &mDoc;
424 bool mGMLUsed;
425 QgsOgcUtils::GMLVersion mGMLVersion;
426 QgsOgcUtils::FilterVersion mFilterVersion;
427 QString mNamespacePrefix;
428 QString mNamespaceURI;
429 QString mGeometryName;
430 QString mSrsName;
431 bool mInvertAxisOrientation;
432 QMap<QString, QString> mFieldNameToXPathMap;
433 QMap<QString, QString> mNamespacePrefixToUriMap;
434 QString mErrorMessage;
435 QString mFilterPrefix;
436 QString mPropertyName;
437 int mGeomId;
438
439 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
440 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
441 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
442 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
443 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
444 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
445};
446
454{
455 public:
456
463 const QgsVectorLayer *layer = nullptr );
464
470 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
471
476 QString errorMessage() const;
477
484
489 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
490
495 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
496
501 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
502
507 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
508
514
519 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
520
525 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
526
527 private:
528 const QgsVectorLayer *mLayer = nullptr;
529 QString mErrorMessage;
530 QString mPropertyName;
531 QString mPrefix;
532};
533
540{
541 public:
543 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
544 QgsOgcUtils::GMLVersion gmlVersion,
545 QgsOgcUtils::FilterVersion filterVersion,
546 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
547 bool honourAxisOrientation,
548 bool invertAxisOrientation,
549 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
550 const QMap<QString, QString> &fieldNameToXPathMap,
551 const QMap<QString, QString> &namespacePrefixToUriMap );
552
554 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
555
557 bool GMLNamespaceUsed() const { return mGMLUsed; }
558
560 QString errorMessage() const { return mErrorMessage; }
561
562 private:
563 QDomDocument &mDoc;
564 bool mGMLUsed;
565 QgsOgcUtils::GMLVersion mGMLVersion;
566 QgsOgcUtils::FilterVersion mFilterVersion;
567 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
568 bool mHonourAxisOrientation;
569 bool mInvertAxisOrientation;
570 QString mErrorMessage;
571 QString mFilterPrefix;
572 QString mPropertyName;
573 int mGeomId;
574 QString mCurrentSRSName;
575 QMap<QString, QString> mMapTableAliasToNames;
576 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
577 const QMap<QString, QString> &mFieldNameToXPathMap;
578 const QMap<QString, QString> &mNamespacePrefixToUriMap;
579
580 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
581 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
582 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
583 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
584 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
585 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
586 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
587 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
588 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
589
590 void visit( const QgsSQLStatement::NodeTableDef *node );
591 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
592 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
593 QList<QgsSQLStatement::Node *> args,
594 bool lastArgIsSRSName,
595 QString &srsName,
596 bool &axisInversion );
597};
598
605class CORE_EXPORT QgsOgcCrsUtils
606{
607 public:
608
610 enum class CRSFlavor
611 {
612 UNKNOWN,
613 AUTH_CODE,
614 HTTP_EPSG_DOT_XML,
615 OGC_URN,
616 X_OGC_URN,
617 OGC_HTTP_URI,
618 };
619
629 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
630};
631
633
634#endif // #ifndef SIP_RUN
635
636#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:80
Utilities related to OGC CRS encodings.
CRSFlavor
CRS flavor.
QgsOgcUtilsExprToFilter(QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, QgsOgcUtils::FilterVersion filterVersion, const QString &namespacePrefix, const QString &namespaceURI, const QString &geometryName, const QString &srsName, bool honourAxisOrientation, bool invertAxisOrientation, const QMap< QString, QString > &fieldNameToXPathMap, const QMap< QString, QString > &namespacePrefixToUriMap)
Constructor.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
QDomElement expressionNodeToOgcFilter(const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context)
Convert an expression to a OGC filter.
QString errorMessage() const
Returns the error message.
QgsExpressionNodeFunction * nodeSpatialOperatorFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with spatial operators.
QgsExpressionNodeUnaryOperator * nodeNotFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with Not operator.
QgsExpressionNodeColumnRef * nodeColumnRefFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with column references.
QgsExpressionNode * nodeIsBetweenFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with boundaries operator.
QgsOgcUtilsExpressionFromFilter(QgsOgcUtils::FilterVersion version=QgsOgcUtils::FILTER_OGC_1_0, const QgsVectorLayer *layer=nullptr)
Constructor for QgsOgcUtilsExpressionFromFilter.
QgsExpressionNodeBinaryOperator * nodeBinaryOperatorFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with binary operators.
QgsExpressionNodeFunction * nodeFunctionFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with functions.
QgsExpressionNode * nodeFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document element.
QgsExpressionNodeBinaryOperator * nodePropertyIsNullFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with IsNull operator.
QString errorMessage() const
Returns the underlying error message, or an empty string in case of no error.
QgsExpressionNode * nodeLiteralFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with literal tag.
QgsOgcUtilsSQLStatementToFilter(QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, QgsOgcUtils::FilterVersion filterVersion, const QList< QgsOgcUtils::LayerProperties > &layerProperties, bool honourAxisOrientation, bool invertAxisOrientation, const QMap< QString, QString > &mapUnprefixedTypenameToPrefixedTypename, const QMap< QString, QString > &fieldNameToXPathMap, const QMap< QString, QString > &namespacePrefixToUriMap)
Constructor.
QDomElement toOgcFilter(const QgsSQLStatement::Node *node)
Convert a SQL statement to a OGC filter.
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:56
GMLVersion
GML version.
Definition qgsogcutils.h:82
FilterVersion
OGC filter version.
static QDomElement SQLStatementToOgcFilter(const QgsSQLStatement &statement, QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, const QList< LayerProperties > &layerProperties, bool honourAxisOrientation, bool invertAxisOrientation, const QMap< QString, QString > &mapUnprefixedTypenameToPrefixedTypename, QString *errorMessage=nullptr, const QMap< QString, QString > &fieldNameToXPathMap=QMap< QString, QString >(), const QMap< QString, QString > &namespacePrefixToUriMap=QMap< QString, QString >())
Creates OGC filter XML element from the WHERE and JOIN clauses of a SQL statement.
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:61
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition qgsgeometry.h:70
The Context struct stores the current layer and coordinate transform context.
Definition qgsogcutils.h:64
const QgsMapLayer * layer
Definition qgsogcutils.h:74
Context(const QgsMapLayer *layer=nullptr, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructs a Context from layer and transformContext.
Definition qgsogcutils.h:69
QgsCoordinateTransformContext transformContext
Definition qgsogcutils.h:75