QGIS API Documentation 4.1.0-Master (60fea48833c)
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:
74
84
92 static QgsGeometry geometryFromGML( const QString &xmlString, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
93
97 static QgsGeometry geometryFromGML( const QDomNode &geometryNode, const QgsOgcUtils::Context &context = QgsOgcUtils::Context() );
98
100 static QgsRectangle rectangleFromGMLBox( const QDomNode &boxNode );
101
103 static QgsRectangle rectangleFromGMLEnvelope( const QDomNode &envelopeNode );
104
109 static QDomElement geometryToGML(
110 const QgsGeometry &geometry, QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, const QString &srsName, bool invertAxisOrientation, const QString &gmlIdBase, int precision = 17
111 );
112
117 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
118
123 static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
124
129 static QDomElement rectangleToGMLBox( const QgsRectangle *box, QDomDocument &doc, int precision = 17 );
130
135 static QDomElement rectangleToGMLBox( const QgsRectangle *box, QDomDocument &doc, const QString &srsName, bool invertAxisOrientation, int precision = 17 );
136
141 static QDomElement rectangleToGMLEnvelope( const QgsRectangle *env, QDomDocument &doc, int precision = 17 );
142
147 static QDomElement rectangleToGMLEnvelope( const QgsRectangle *env, QDomDocument &doc, const QString &srsName, bool invertAxisOrientation, int precision = 17 );
148
149
151 static QColor colorFromOgcFill( const QDomElement &fillElement );
152
154 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
155
162 static QDomElement expressionToOgcFilter( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr );
163
173
181 static QgsExpression *expressionFromOgcFilter( const QDomElement &element, FilterVersion version, QgsVectorLayer *layer = nullptr ) SIP_FACTORY;
182
190 static QDomElement expressionToOgcFilter(
191 const QgsExpression &exp,
192 QDomDocument &doc,
193 QgsOgcUtils::GMLVersion gmlVersion,
194 FilterVersion filterVersion,
195 const QString &namespacePrefix,
196 const QString &namespaceURI,
197 const QString &geometryName,
198 const QString &srsName,
199 bool honourAxisOrientation,
200 bool invertAxisOrientation,
201 QString *errorMessage = nullptr,
202 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
203 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>()
204 ) SIP_SKIP;
205
212 static QDomElement expressionToOgcExpression( const QgsExpression &exp, QDomDocument &doc, QString *errorMessage = nullptr, bool requiresFilterElement = false );
213
219 static QDomElement elseFilterExpression( QDomDocument &doc );
220
226 static QDomElement expressionToOgcExpression(
227 const QgsExpression &exp,
228 QDomDocument &doc,
229 QgsOgcUtils::GMLVersion gmlVersion,
230 FilterVersion filterVersion,
231 const QString &geometryName,
232 const QString &srsName,
233 bool honourAxisOrientation,
234 bool invertAxisOrientation,
235 QString *errorMessage = nullptr,
236 bool requiresFilterElement = false,
237 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
238 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>()
239 );
240
241#ifndef SIP_RUN
242
249 {
250 public:
251 LayerProperties() = default;
252
254 QString mName;
258 QString mSRSName;
263 };
264#endif
265
283 static QDomElement SQLStatementToOgcFilter(
284 const QgsSQLStatement &statement,
285 QDomDocument &doc,
286 QgsOgcUtils::GMLVersion gmlVersion,
287 FilterVersion filterVersion,
288 const QList<LayerProperties> &layerProperties,
289 bool honourAxisOrientation,
290 bool invertAxisOrientation,
291 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
292 QString *errorMessage = nullptr,
293 const QMap<QString, QString> &fieldNameToXPathMap = QMap<QString, QString>(),
294 const QMap<QString, QString> &namespacePrefixToUriMap = QMap<QString, QString>()
295 ) SIP_SKIP;
296
303 static Qgis::WkbType geomTypeFromPropertyType( const QString &gmlGeomType ) SIP_SKIP;
304
305 private:
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( QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, bool GMLUsed );
328
335 static bool readGMLCoordinates( QgsPolyline &coords, const QDomElement &elem );
336
345 static bool readGMLPositions( QgsPolyline &coords, const QDomElement &elem );
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
384#ifndef SIP_RUN
385
392{
393 public:
396 QDomDocument &doc,
397 QgsOgcUtils::GMLVersion gmlVersion,
398 QgsOgcUtils::FilterVersion filterVersion,
399 const QString &namespacePrefix,
400 const QString &namespaceURI,
401 const QString &geometryName,
402 const QString &srsName,
403 bool honourAxisOrientation,
404 bool invertAxisOrientation,
405 const QMap<QString, QString> &fieldNameToXPathMap,
406 const QMap<QString, QString> &namespacePrefixToUriMap
407 );
408
410 QDomElement expressionNodeToOgcFilter( const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context );
411
413 bool GMLNamespaceUsed() const { return mGMLUsed; }
414
416 QString errorMessage() const { return mErrorMessage; }
417
418 private:
419 QDomDocument &mDoc;
420 bool mGMLUsed = false;
421 QgsOgcUtils::GMLVersion mGMLVersion;
422 QgsOgcUtils::FilterVersion mFilterVersion;
423 QString mNamespacePrefix;
424 QString mNamespaceURI;
425 QString mGeometryName;
426 QString mSrsName;
427 bool mInvertAxisOrientation;
428 QMap<QString, QString> mFieldNameToXPathMap;
429 QMap<QString, QString> mNamespacePrefixToUriMap;
430 QString mErrorMessage;
431 QString mFilterPrefix;
432 QString mPropertyName;
433 int mGeomId = 1;
434
435 QDomElement expressionUnaryOperatorToOgcFilter( const QgsExpressionNodeUnaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
436 QDomElement expressionBinaryOperatorToOgcFilter( const QgsExpressionNodeBinaryOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
437 QDomElement expressionLiteralToOgcFilter( const QgsExpressionNodeLiteral *node, QgsExpression *expression, const QgsExpressionContext *context );
438 QDomElement expressionColumnRefToOgcFilter( const QgsExpressionNodeColumnRef *node, QgsExpression *expression, const QgsExpressionContext *context );
439 QDomElement expressionInOperatorToOgcFilter( const QgsExpressionNodeInOperator *node, QgsExpression *expression, const QgsExpressionContext *context );
440 QDomElement expressionFunctionToOgcFilter( const QgsExpressionNodeFunction *node, QgsExpression *expression, const QgsExpressionContext *context );
441};
442
450{
451 public:
458
464 QgsExpressionNode *nodeFromOgcFilter( const QDomElement &element );
465
470 QString errorMessage() const;
471
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
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:
538 QDomDocument &doc,
539 QgsOgcUtils::GMLVersion gmlVersion,
540 QgsOgcUtils::FilterVersion filterVersion,
541 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
542 bool honourAxisOrientation,
543 bool invertAxisOrientation,
544 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
545 const QMap<QString, QString> &fieldNameToXPathMap,
546 const QMap<QString, QString> &namespacePrefixToUriMap
547 );
548
550 QDomElement toOgcFilter( const QgsSQLStatement::Node *node );
551
553 bool GMLNamespaceUsed() const { return mGMLUsed; }
554
556 QString errorMessage() const { return mErrorMessage; }
557
558 private:
559 QDomDocument &mDoc;
560 bool mGMLUsed = false;
561 QgsOgcUtils::GMLVersion mGMLVersion;
562 QgsOgcUtils::FilterVersion mFilterVersion;
563 const QList<QgsOgcUtils::LayerProperties> &mLayerProperties;
564 bool mHonourAxisOrientation;
565 bool mInvertAxisOrientation;
566 QString mErrorMessage;
567 QString mFilterPrefix;
568 QString mPropertyName;
569 int mGeomId = 1;
570 QString mCurrentSRSName;
571 QMap<QString, QString> mMapTableAliasToNames;
572 const QMap< QString, QString> &mMapUnprefixedTypenameToPrefixedTypename;
573 const QMap<QString, QString> &mFieldNameToXPathMap;
574 const QMap<QString, QString> &mNamespacePrefixToUriMap;
575
576 QDomElement toOgcFilter( const QgsSQLStatement::NodeUnaryOperator *node );
577 QDomElement toOgcFilter( const QgsSQLStatement::NodeBinaryOperator *node );
578 QDomElement toOgcFilter( const QgsSQLStatement::NodeLiteral *node );
579 QDomElement toOgcFilter( const QgsSQLStatement::NodeColumnRef *node );
580 QDomElement toOgcFilter( const QgsSQLStatement::NodeInOperator *node );
581 QDomElement toOgcFilter( const QgsSQLStatement::NodeBetweenOperator *node );
582 QDomElement toOgcFilter( const QgsSQLStatement::NodeFunction *node );
583 QDomElement toOgcFilter( const QgsSQLStatement::NodeJoin *node, const QString &leftTable );
584 QDomElement toOgcFilter( const QgsSQLStatement::NodeSelect *node );
585
586 void visit( const QgsSQLStatement::NodeTableDef *node );
587 QString getGeometryColumnSRSName( const QgsSQLStatement::Node *node );
588 bool processSRSName( const QgsSQLStatement::NodeFunction *mainNode, QList<QgsSQLStatement::Node *> args, bool lastArgIsSRSName, QString &srsName, bool &axisInversion );
589};
590
597class CORE_EXPORT QgsOgcCrsUtils
598{
599 public:
601 enum class CRSFlavor
602 {
603 UNKNOWN,
604 AUTH_CODE,
605 HTTP_EPSG_DOT_XML,
606 OGC_URN,
607 X_OGC_URN,
608 OGC_HTTP_URI,
609 };
610
620 static CRSFlavor parseCrsName( const QString &crsName, QString &authority, QString &code );
621};
622
624
625#endif // #ifndef SIP_RUN
626
627#endif // QGSOGCUTILS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
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:83
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:79
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:62
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:133
#define SIP_FACTORY
Definition qgis_sip.h:83
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:63
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition qgsgeometry.h:72
The Context struct stores the current layer and coordinate transform context.
Definition qgsogcutils.h:63
const QgsMapLayer * layer
Definition qgsogcutils.h:71
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:72