gws.plugin.qgis.caps

QGIS project xml parser.

Source code: gws.plugin.qgis.caps

Module Contents

class gws.plugin.qgis.caps.Caps(*args, **kwargs)

Bases: gws.Data

Capabilities of a QGIS project, as parsed from the project XML.

metadata: gws.Metadata

Project metadata.

printTemplates: list[PrintTemplate]

Print layouts.

projectBounds: gws.Bounds | None

Explicit WMS extent of the project, if set.

projectCanvasBounds: gws.Bounds | None

Map canvas extent of the project, if set.

projectCrs: gws.Crs

4326 if the project has none.

Type:

Project CRS, EPSG

properties: dict

Project properties.

sourceLayers: list[gws.SourceLayer]

Top-level layers and groups of the project layer tree.

version: str

QGIS version that wrote the project.

visibilityPresets: dict[str, list[str]]

Map themes, mapping a theme name to the IDs of visible layers.

gws.plugin.qgis.caps.parse(xml: str) → Caps

Parse a QGIS project XML string.

Parameters:

xml – Project XML.

Returns:

Project capabilities.

Raises:

gws.Error – If the project CRS is invalid.

gws.plugin.qgis.caps.parse_datasource(prov, text)

Parse a QGIS layer data source string.

Common formats (ampersand-delimited, space-delimited, plain URL, pipe-delimited path) are parsed into a dict with lower-case keys, anything else is returned as {'text': text}. The provider key is always set; WMS sources with a tile matrix set are classified as wmts, and WMS sources of type xyz as xyz.

Parameters:
  • prov – Data provider name from the project, e.g. postgres.

  • text – Data source string.

Returns:

Data source properties.

Raises:

ValueError – If a space- or pipe-delimited string is malformed.

gws.plugin.qgis.caps.parse_element(root_el: gws.XmlElement) → Caps

Parse a QGIS project XML element.

Layers listed as restricted in the project WMS settings are skipped.

Parameters:

root_el – Root element of the project XML.

Returns:

Project capabilities.

Raises:

gws.Error – If the project CRS is invalid.

class gws.plugin.qgis.caps.PrintTemplate(*args, **kwargs)

Bases: gws.Data

A QGIS print layout.

attributes: dict

XML attributes of the layout element.

elements: list[PrintTemplateElement]

Pages and items of the layout.

index: int

Position of the layout in the project, starting with 0.

title: str

Layout name.

class gws.plugin.qgis.caps.PrintTemplateElement(*args, **kwargs)

Bases: gws.Data

An item of a QGIS print layout.

attributes: dict

XML attributes of the item element.

position: gws.UomPoint

Position of the item on the page.

size: gws.UomSize

Size of the item.

type: str

Item type, e.g. map, label or page.

uuid: str

Item UUID.

gws.plugin.qgis.caps.qgis_extent(layer_el: gws.XmlElement, layer_crs: gws.Crs)

Compute the WGS extent of a map layer.

The extent is taken from the first valid source of the following: the explicit extent in the layer metadata, the wgs84extent element, and the extent element, which is assumed to be in the layer CRS.

Parameters:
  • layer_el – maplayer element.

  • layer_crs – CRS of the layer.

Returns:

WGS extent, or None if no valid extent is found.