gws.plugin.qgis.provider

QGIS project provider.

Source code: gws.plugin.qgis.provider

Module Contents

class gws.plugin.qgis.provider.Config(*args, **kwargs)

Bases: gws.Config

QGIS project, served by QGIS Server.

dbUid: str | None

Database provider UID for projects stored in a database.

defaultLegendOptions: dict | None

Legend options applied to all layers of this project.

directRender: list[str] | None

Layer sources to load directly, not through QGIS Server.

directSearch: list[str] | None

Layer sources to search directly, not through QGIS Server.

extentBuffer: int | None

Buffer around the extent computed from layer data.

forceCrs: gws.CrsName | None

CRS for QGIS Server requests.

path: gws.FilePath | None

QGIS project file.

projectName: str | None

Project name for projects stored in a database.

schema: str | None

Database schema for projects stored in a database.

useCanvasExtent: bool | None

Use the map canvas extent when the project has no WMS extent.

watchFrequency: gws.Duration | None

Interval between checks for project changes.

withWatch: bool | None

Reload the application when the QGIS project changes.

class gws.plugin.qgis.provider.Object

Bases: gws.OwsServiceProvider

Provider for a QGIS project, served by QGIS Server.

The provider loads and parses the project, computes the project bounds and sends requests to QGIS Server.

caps: gws.plugin.qgis.caps.Caps

Parsed project capabilities.

defaultLegendOptions: dict

Legend options applied to all layers of the project.

directRender: set[str]

Data source providers rendered directly, not through QGIS Server (wms, wmts, xyz).

directSearch: set[str]

Data source providers searched directly, not through QGIS Server (wms, wfs, postgres).

printTemplates: list[gws.plugin.qgis.caps.PrintTemplate]

Print layouts of the project.

sourceHash: str

Hash of the project XML when watching is enabled, otherwise empty.

store: gws.plugin.qgis.project.Store

Location of the project.

cache_hash()

Compute a hash of the provider settings that affect rendering.

Returns:

Hash string, built from the store and the request CRS.

call_server(params: dict) → gws.lib.net.HTTPResponse

Send a request to QGIS Server.

Parameters:

params – Request parameters, completed by server_params.

Returns:

HTTP response.

Raises:

gws.lib.net.Error – If the request fails.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

configure_store()

Set the project store from path or projectName.

Raises:

gws.ConfigurationError – If neither path nor projectName is configured.

create_leaf_layer_config(source_layers)

Create the configuration of a leaf layer for the qgis tree layer.

By default, this is a qgisflat layer. For a single source layer whose data source provider is listed in directRender or directSearch, the layer is rendered directly (wmsflat, wmts or tile) and gets its own finders and models.

Parameters:

source_layers – Source layers of the leaf.

Returns:

Layer configuration dict.

get_features(search, source_layers)

Search for features in the given source layers.

Parameters:
  • args – Search query.

  • source_layers – Source layers to search.

Returns:

Found feature records.

get_map(bounds: gws.Bounds, width: float, height: float, params: dict) → bytes

Render a map image with a GetMap request.

Parameters:
  • bounds – Box to render.

  • width – Image width in pixels.

  • height – Image height in pixels.

  • params – Extra request parameters, e.g. LAYERS; they override the defaults (transparent PNG).

Returns:

Image bytes.

Raises:

gws.Error – If QGIS Server returns a non-image response.

periodic_task()

Periodic task hook.

Called by the server monitor for nodes registered with register_periodic_task.

postgres_provider_from_datasource(ds: dict) → gws.plugin.postgres.provider.Object

Find or create a Postgres provider for a QGIS data source.

An existing provider with the same connection URL is reused, otherwise a new provider is created.

Parameters:

ds – Parsed Postgres data source.

Returns:

Postgres provider.

qgis_project() → gws.plugin.qgis.project.Object

Load the project from its store.

Returns:

A freshly loaded project.

Raises:

project.Error – If the project cannot be loaded.

server_params(params: dict) → dict

Add default parameters to a QGIS Server request.

Parameters:

params – Request parameters; keys are converted to upper case.

Returns:

Parameters with MAP, SERVICE and VERSION defaults.

server_project_path()

Return the project address for the QGIS Server MAP parameter.

For a file store this is the file path. For a Postgres store this is the database connection URL with schema and project parameters; when watching is enabled, the project hash is appended to invalidate the QGIS Server cache.

Returns:

Project path or URL.