Skip to content

Usage of Exporter

Generate QGIS Project config

By separating QGIS project information from the servers runtime we save a lot of headaches and be sure to have the server know only what it should know. With that we minimize the amount of potential bugs drastically. There is another idea embedded here. Thinking of a big amount of QGIS projects with a ton of layer in each served by 4 instances of QGIS-Server (in a classical setup) for load balancing reasons as WMS. This means each server has to solve several tasks (Capabilities, Rendering, LayerTree knowledge etc.). Not only that rendering a WMS request does not need any knowledge of a tree structure but a one dimensional ordered stacking list of layers. Serving the capabilities with lets say a permission system is not being implemented easily.

However, this comes with a downside:

  • We need to extract this information from a QGIS-Project to feed the server with it at runtime to empower it for rendering our requested layers.

QGIS-Server-Light gives you a typed way (python lib) to store extracted information of a QGIS project. This is what you can use programmatically in your 3rd party application. In addition, it offers a CLI to just do a command line call to extract the information.

Using the CLI

You can extract information of a QGIS-Project inside the container (see Docker-DEV) like this:

docker compose run --rm -T --entrypoint bash worker -c "uv run python -m qgis_server_light.exporter.cli export --project /io/data/[path-to-your-project]"

The project has to be located in LOCAL_PROJECTS which is mounted to /io/data.

This uses the default output format json and does not unify layer names in the project.

❗ This command writes to stdout!

If you want to save the output to a file, you can do by:

docker compose run --rm -T --entrypoint bash worker -c "uv run python -m qgis_server_light.exporter.cli export --project /io/data/[path-to-your-project]" > project_config.json

Supported QGIS project extensions

  • qgs
  • qgz

Supported output formats

--output_format

  • json (default)
  • xml

Unify layer names

--unify_layer_names_by_group

  • False (default)
  • True

There is an option unify_layer_names_by_group. It allows you to reflect the structure of your tree in the layer names.

Let's say you have a tree structure like that:

environment
├── ground_coverage
│   ├── forest
│   ├── field
│   └── lake
└── forest

And presume it is the layer names we see. So the short name which is the name used for exposition to WMS. This would end up in forest being not addressable in a WMS request easily unless we would use the layer id of QGIS project layer. But this is not so nicely read in the capabilities in the end.

So enabling this option, will produce the following names for the layers:

  • environment.forest
  • environment.ground_coverage.forest
  • environment.ground_coverage.field
  • environment.ground_coverage.lake

Warnings and errors

Problems found while exporting a project are reported as structured messages. Each message has:

  • level: warning or error
  • code: a stable identifier
  • message: a human-readable description
  • layer_id: the QGIS layer id, if the message concerns a layer

A warning does not stop the export. The exported config is written to stdout as usual and contains the warnings in its messages field. The affected layer or tree node may be left out of the config.

An error stops the export. The CLI writes a result containing the "messages" to stdout (in the requested output format) and exits with code 3. The exporter API answers with successful: false and this result as content. Other non-zero exit codes are reported as an unexpected_error message.