QgsOgcUtils class

The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial Consortium) standards and QGIS internal representations.

Currently supported standards:

  • GML2 - Geography Markup Language (import, export)

Public types

class LayerProperties
Layer properties.
enum FilterVersion { FILTER_OGC_1_0, FILTER_OGC_1_1, FILTER_FES_2_0 }
OGC filter version.
enum GMLVersion { GML_2_1_2, GML_3_1_0, GML_3_2_1 }
GML version.

Public static functions

static auto colorFromOgcFill(const QDomElement& fillElement) -> QColor
Parse XML with OGC fill into QColor.
static auto expressionFromOgcFilter(const QDomElement& element, QgsVectorLayer* layer = nullptr) -> QgsExpression*
Parse XML with OGC filter into QGIS expression.
static auto expressionFromOgcFilter(const QDomElement& element, FilterVersion version, QgsVectorLayer* layer = nullptr) -> QgsExpression*
Returns an expression from a WFS filter embedded in a document.
static auto expressionToOgcExpression(const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr) -> QDomElement
Creates an OGC expression XML element.
static auto expressionToOgcExpression(const QgsExpression& exp, QDomDocument& doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, const QString& geometryName, const QString& srsName, bool honourAxisOrientation, bool invertAxisOrientation, QString* errorMessage = nullptr) -> QDomElement
Creates an OGC expression XML element.
static auto expressionToOgcFilter(const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr) -> QDomElement
Creates OGC filter XML element.
static auto expressionToOgcFilter(const QgsExpression& exp, QDomDocument& doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, const QString& geometryName, const QString& srsName, bool honourAxisOrientation, bool invertAxisOrientation, QString* errorMessage = nullptr) -> QDomElement
Creates OGC filter XML element.
static auto geometryFromGML(const QString& xmlString) -> QgsGeometry
Static method that creates geometry from GML.
static auto geometryFromGML(const QDomNode& geometryNode) -> QgsGeometry
Static method that creates geometry from GML.
static auto geometryToGML(const QgsGeometry& geometry, QDomDocument& doc, QgsOgcUtils::GMLVersion gmlVersion, const QString& srsName, bool invertAxisOrientation, const QString& gmlIdBase, int precision = 17) -> QDomElement
Exports the geometry to GML.
static auto geometryToGML(const QgsGeometry& geometry, QDomDocument& doc, const QString& format, int precision = 17) -> QDomElement
Exports the geometry to GML2 or GML3.
static auto geometryToGML(const QgsGeometry& geometry, QDomDocument& doc, int precision = 17) -> QDomElement
Exports the geometry to GML2.
static auto rectangleFromGMLBox(const QDomNode& boxNode) -> QgsRectangle
Read rectangle from GML2 Box.
static auto rectangleFromGMLEnvelope(const QDomNode& envelopeNode) -> QgsRectangle
Read rectangle from GML3 Envelope.
static auto rectangleToGMLBox(QgsRectangle* box, QDomDocument& doc, int precision = 17) -> QDomElement
Exports the rectangle to GML2 Box.
static auto rectangleToGMLBox(QgsRectangle* box, QDomDocument& doc, const QString& srsName, bool invertAxisOrientation, int precision = 17) -> QDomElement
Exports the rectangle to GML2 Box.
static auto rectangleToGMLEnvelope(QgsRectangle* env, QDomDocument& doc, int precision = 17) -> QDomElement
Exports the rectangle to GML3 Envelope.
static auto rectangleToGMLEnvelope(QgsRectangle* env, QDomDocument& doc, const QString& srsName, bool invertAxisOrientation, int precision = 17) -> QDomElement
Exports the rectangle to GML3 Envelope.
static auto 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) -> QDomElement
Creates OGC filter XML element from the WHERE and JOIN clauses of a SQL statement.

Function documentation

static QgsExpression* QgsOgcUtils::expressionFromOgcFilter(const QDomElement& element, FilterVersion version, QgsVectorLayer* layer = nullptr)

Returns an expression from a WFS filter embedded in a document.

Parameters
element The WFS Filter
version The WFS version
layer Layer to use to retrieve field values from literal filters

static QDomElement QgsOgcUtils::expressionToOgcExpression(const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr)

Creates an OGC expression XML element.

Returns valid OGC expression QDomElement on success, otherwise null QDomElement

static QDomElement QgsOgcUtils::expressionToOgcExpression(const QgsExpression& exp, QDomDocument& doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, const QString& geometryName, const QString& srsName, bool honourAxisOrientation, bool invertAxisOrientation, QString* errorMessage = nullptr)

Creates an OGC expression XML element.

Returns valid OGC expression QDomElement on success, otherwise null QDomElement

static QDomElement QgsOgcUtils::expressionToOgcFilter(const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr)

Creates OGC filter XML element.

Returns

valid

<Filter> 

QDomElement on success, otherwise null QDomElement

Supports minimum standard filter according to the OGC filter specs (=,!=,<,>,<=,>=,AND,OR,NOT)

static QDomElement QgsOgcUtils::expressionToOgcFilter(const QgsExpression& exp, QDomDocument& doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, const QString& geometryName, const QString& srsName, bool honourAxisOrientation, bool invertAxisOrientation, QString* errorMessage = nullptr)

Creates OGC filter XML element.

Returns

valid

<Filter> 

QDomElement on success, otherwise null QDomElement

Supports minimum standard filter according to the OGC filter specs (=,!=,<,>,<=,>=,AND,OR,NOT)

static QgsGeometry QgsOgcUtils::geometryFromGML(const QString& xmlString)

Static method that creates geometry from GML.

Parameters
xmlString

xml representation of the geometry. GML elements are expected to be in default namespace (

{<Point>...</Point> 

) or in "gml" namespace (

<gml:Point>...</gml:Point> 

)

static QDomElement QgsOgcUtils::geometryToGML(const QgsGeometry& geometry, QDomDocument& doc, QgsOgcUtils::GMLVersion gmlVersion, const QString& srsName, bool invertAxisOrientation, const QString& gmlIdBase, int precision = 17)

Exports the geometry to GML.

Returns QDomElement

static QDomElement QgsOgcUtils::geometryToGML(const QgsGeometry& geometry, QDomDocument& doc, const QString& format, int precision = 17)

Exports the geometry to GML2 or GML3.

Returns QDomElement

static QDomElement QgsOgcUtils::geometryToGML(const QgsGeometry& geometry, QDomDocument& doc, int precision = 17)

Exports the geometry to GML2.

Returns QDomElement

static QDomElement QgsOgcUtils::rectangleToGMLBox(QgsRectangle* box, QDomDocument& doc, int precision = 17)

Exports the rectangle to GML2 Box.

Returns QDomElement

static QDomElement QgsOgcUtils::rectangleToGMLBox(QgsRectangle* box, QDomDocument& doc, const QString& srsName, bool invertAxisOrientation, int precision = 17)

Exports the rectangle to GML2 Box.

Returns QDomElement

static QDomElement QgsOgcUtils::rectangleToGMLEnvelope(QgsRectangle* env, QDomDocument& doc, int precision = 17)

Exports the rectangle to GML3 Envelope.

Returns QDomElement

static QDomElement QgsOgcUtils::rectangleToGMLEnvelope(QgsRectangle* env, QDomDocument& doc, const QString& srsName, bool invertAxisOrientation, int precision = 17)

Exports the rectangle to GML3 Envelope.

Returns QDomElement

static QDomElement QgsOgcUtils::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)

Creates OGC filter XML element from the WHERE and JOIN clauses of a SQL statement.

Returns

valid

<Filter> 

QDomElement on success, otherwise null QDomElement

Supports minimum standard filter according to the OGC filter specs (=,!=,<,>,<=,>=,AND,OR,NOT,LIKE,BETWEEN,IN) Supports layer joins. Supports ST_GeometryFromText(wkt[, srid/srsname]), ST_MakeEnvelope(xmin,ymin,xmax,ymax[, srid/srsname]) ST_GeomFromGML(serialized_gml_string) BBOX() ST_Intersects(), ST_Contains(), ST_Crosses(), ST_Equals(), ST_Disjoint(), ST_Overlaps(), ST_Touches(), ST_Within() ST_DWithin(), ST_Beyond() custom functions