gws.plugin.qgis.project

Loading and storing QGIS projects.

Source code: gws.plugin.qgis.project

Module Contents

exception gws.plugin.qgis.project.Error

Bases: gws.Error

QGIS project error.

gws.plugin.qgis.project.from_path(path: str) → Object

Load a QGIS project from a .qgs or .qgz file.

Parameters:

path – Project file path.

Returns:

The project.

Raises:

Error – If a .qgz archive contains no project or the QGIS version is not supported.

gws.plugin.qgis.project.from_store(root: gws.Root, store: Store) → Object

Load a QGIS project from a store.

Parameters:
  • root – Root object, used to find the database provider.

  • store – Project location.

Returns:

The project.

Raises:

Error – If the project cannot be found or loaded.

gws.plugin.qgis.project.from_string(text: str) → Object

Create a QGIS project from XML text.

Parameters:

text – Project XML.

Returns:

The project.

Raises:

Error – If the QGIS version is not supported.

class gws.plugin.qgis.project.Object(text: str)

A QGIS project, held as XML text.

Only QGIS 3 projects are supported. The parsed XML tree is created on demand and is not pickled.

sourceHash: str

SHA-256 hash of the project XML text.

text
version: str

QGIS version that wrote the project, e.g. 3.34.0.

caps() → gws.plugin.qgis.caps.Caps

Parse the project capabilities.

Returns:

Project capabilities.

Raises:

gws.Error – If the project CRS is invalid.

to_path(path: str)

Save the project to a file.

If the path ends with .qgz, the project is saved as a zip archive.

Parameters:

path – File path.

to_store(root: gws.Root, store: Store)

Save the project to a store.

In a Postgres store, an existing project with the same name is renamed to <name>.bak, replacing an older backup.

Parameters:
  • root – Root object, used to find the database provider.

  • store – Project location.

Raises:

Error – If the store type is not supported.

to_xml()

Serialize the project XML.

Returns:

Project XML text.

xml_root() → gws.XmlElement

Return the root element of the project XML.

The XML is parsed on the first call. Changes to the tree are kept and written by to_xml, to_path and to_store.

Returns:

Root element.

class gws.plugin.qgis.project.Store(*args, **kwargs)

Bases: gws.Data

Location of a QGIS project.

dbUid: str

Database provider UID, for Postgres stores.

path: gws.FilePath

Project file path, for file stores.

projectName: str

Project name.

schema: str

Schema of the projects table, for Postgres stores. Defaults to public.

type: StoreType

Store type.

class gws.plugin.qgis.project.StoreType

Bases: gws.Enum

Where a QGIS project is stored.

file = 'file'

Project file (.qgs or .qgz).

postgres = 'postgres'

Postgres table qgis_projects.