QGIS API Documentation 3.99.0-Master (a8882ad4560)
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
310 static Qgis::WkbType geomTypeFromPropertyType( const QString &gmlGeomType ) SIP_SKIP;
311
312 private:
313
315 static QgsGeometry geometryFromGMLPoint( const QDomElement &geometryElement );
317 static QgsGeometry geometryFromGMLLineString( const QDomElement &geometryElement );
319 static QgsGeometry geometryFromGMLPolygon( const QDomElement &geometryElement );
321 static QgsGeometry geometryFromGMLMultiPoint( const QDomElement &geometryElement );
323 static QgsGeometry geometryFromGMLMultiLineString( const QDomElement &geometryElement );
325 static QgsGeometry geometryFromGMLMultiCurve( const QDomElement &geometryElement );
327 static QgsGeometry geometryFromGMLMultiPolygon( const QDomElement &geometryElement );
329 static QgsGeometry geometryFromGMLUsingGdal( const QDomElement &geometryElement );
330
335 static QDomElement filterElement(
336 QDomDocument &doc,
337 QgsOgcUtils::GMLVersion gmlVersion,
338 FilterVersion filterVersion,
339 bool GMLUsed );
340
347 static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
348
357 static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
358
365 static QDomElement createGMLCoordinates( const QgsPolylineXY &points, QDomDocument &doc );
366
373 static QDomElement createGMLPositions( const QgsPolylineXY &points, QDomDocument &doc );
374
376 static QgsExpressionNode *nodeFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
378 static QgsExpressionNodeBinaryOperator *nodeBinaryOperatorFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
380 static QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( QDomElement &element, QString &errorMessage );
382 static QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( QDomElement &element, QString &errorMessage );
384 static QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( QDomElement &element, QString &errorMessage );
386 static QgsExpressionNode *nodeLiteralFromOgcFilter( QDomElement &element, QString &errorMessage, QgsVectorLayer *layer = nullptr );
388 static QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( QDomElement &element, QString &errorMessage );
390 static QgsExpressionNode *nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage );
392 static QgsExpressionNodeBinaryOperator *nodePropertyIsNullFromOgcFilter( QDomElement &element, QString &errorMessage );
393};
394
395
396
397#ifndef SIP_RUN
398
405{
406 public:
408 QgsOgcUtilsExprToFilter( QDomDocument &doc,
409 QgsOgcUtils::GMLVersion gmlVersion,
410 QgsOgcUtils::FilterVersion filterVersion,
411 const QString &namespacePrefix,
412 const QString &namespaceURI,
413 const QString &geometryName,
414 const QString &srsName,
415 bool honourAxisOrientation,
416 bool invertAxisOrientation,
417 const QMap<QString, QString> &fieldNameToXPathMap,
418 const QMap<QString, QString> &namespacePrefixToUriMap
419 );
420
422 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
423
425 bool GMLNamespaceUsed() const { return mGMLUsed; }
426
428 QString errorMessage() const { return mErrorMessage; }
429
430 private:
431 QDomDocument &mDoc;
432 bool mGMLUsed = false;
433 QgsOgcUtils::GMLVersion mGMLVersion;
434 QgsOgcUtils::FilterVersion mFilterVersion;
435 QString mNamespacePrefix;
436 QString mNamespaceURI;
437 QString mGeometryName;
438 QString mSrsName;
439 bool mInvertAxisOrientation;
440 QMap<QString, QString> mFieldNameToXPathMap;
441 QMap<QString, QString> mNamespacePrefixToUriMap;
442 QString mErrorMessage;
443 QString mFilterPrefix;
444 QString mPropertyName;
445 int mGeomId = 1;
446
447 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
448 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
449 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
450 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
451 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
452 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
453};
454
462{
463 public:
464
471 const QgsVectorLayer *layer = nullptr );
472
478 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
479
484 QString errorMessage() const;
485
492
497 QgsExpressionNodeFunction *nodeSpatialOperatorFromOgcFilter( const QDomElement &element );
498
503 QgsExpressionNodeColumnRef *nodeColumnRefFromOgcFilter( const QDomElement &element );
504
509 QgsExpressionNode *nodeLiteralFromOgcFilter( const QDomElement &element );
510
515 QgsExpressionNodeUnaryOperator *nodeNotFromOgcFilter( const QDomElement &element );
516
522
527 QgsExpressionNodeFunction *nodeFunctionFromOgcFilter( const QDomElement &element );
528
533 QgsExpressionNode *nodeIsBetweenFromOgcFilter( const QDomElement &element );
534
535 private:
536 const QgsVectorLayer *mLayer = nullptr;
537 QString mErrorMessage;
538 QString mPropertyName;
539 QString mPrefix;
540};
541
548{
549 public:
551 QgsOgcUtilsSQLStatementToFilter( QDomDocument &doc,
552 QgsOgcUtils::GMLVersion gmlVersion,
553 QgsOgcUtils::FilterVersion filterVersion,
554 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
555 bool honourAxisOrientation,
556 bool invertAxisOrientation,
557 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
558 const QMap<QString, QString> &fieldNameToXPathMap,
559 const QMap<QString, QString> &namespacePrefixToUriMap );
560
562 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
563
565 bool GMLNamespaceUsed() const { return mGMLUsed; }
566
568 QString errorMessage() const { return mErrorMessage; }
569
570 private:
571 QDomDocument &mDoc;
572 bool mGMLUsed = false;
573 QgsOgcUtils::GMLVersion mGMLVersion;
574 QgsOgcUtils::FilterVersion mFilterVersion;
575 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
576 bool mHonourAxisOrientation;
577 bool mInvertAxisOrientation;
578 QString mErrorMessage;
579 QString mFilterPrefix;
580 QString mPropertyName;
581 int mGeomId = 1 ;
582 QString mCurrentSRSName;
583 QMap<QString, QString> mMapTableAliasToNames;
584 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
585 const QMap<QString, QString> &mFieldNameToXPathMap;
586 const QMap<QString, QString> &mNamespacePrefixToUriMap;
587
588 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
589 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
590 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
591 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
592 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
593 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
594 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
595 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
596 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
597
598 void visit( const QgsSQLStatement::NodeTableDef *node );
599 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
600 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode,
601 QList<QgsSQLStatement::Node *> args,
602 bool lastArgIsSRSName,
603 QString &srsName,
604 bool &axisInversion );
605};
606
613class CORE_EXPORT QgsOgcCrsUtils
614{
615 public:
616
618 enum class CRSFlavor
619 {
620 UNKNOWN,
621 AUTH_CODE,
622 HTTP_EPSG_DOT_XML,
623 OGC_URN,
624 X_OGC_URN,
625 OGC_HTTP_URI,
626 };
627
637 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
638};
639
641
642#endif // #ifndef SIP_RUN
643
644#endif // QGSOGCUTILS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
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.
static Qgis::WkbType geomTypeFromPropertyType(const QString &gmlGeomType)
Returns the Qgis::WkbType corresponding to a GML geometry type.
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