Skip to main content

Create QGIS projects programmatically using Python

Project description

qgis-project

qgis-project

PyPI version Python versions Tests Docs License

Create QGIS projects programmatically using Python.

from qgis_project import Project, RasterLayer, RasterStyleBW

proj = Project()
proj.add_layer("dem.tif")                                    # raster, auto-detected
proj.add_layer("boundaries.geojson")                         # vector, auto-detected
proj.add_layer(RasterLayer("dem.tif", style=RasterStyleBW(vmin=0, vmax=3000)))
proj.save("output.qgz")
proj.open()     # launch QGIS for visual inspection

Installation

Install the package:

pip install qgis-project

QGIS is not on PyPI and must be available separately. The recommended approach is a dedicated conda environment:

conda env create -f environment_platform_independent.yml
conda activate qgis-env-pi
pip install qgis-project

Or install QGIS from conda-forge into an existing environment:

conda install -c conda-forge qgis
pip install qgis-project

Usage

Basic project

from qgis_project import Project

proj = Project()
proj.add_layer("dem.tif")
proj.add_layer("roads.geojson")
proj.save("my_project.qgz")
proj.exit()

Layer groups

proj.add_layer(RasterLayer("dem.tif", group="terrain"))
proj.add_layer(RasterLayer("slope.tif", group=["terrain", "derived"]))

Raster styling

from qgis_project import RasterLayer, RasterStyleBW

layer = RasterLayer(
    file="dem.tif",
    name="Elevation",
    group="terrain",
    style=RasterStyleBW(vmin=0, vmax=3000),
)
proj.add_layer(layer)

Open in QGIS

proj.open("output.qgz")      # saves and launches QGIS
proj.print_layer_tree()      # inspect the layer tree in the terminal

Development

Install with dev dependencies:

pip install -e ".[dev]"

Run unit tests (no QGIS required):

pytest -m "not qgis"

Run integration tests (QGIS environment required):

pytest -m qgis

Run the manual visual test:

python scripts/manual_test.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qgis_project-0.3.10.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qgis_project-0.3.10-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file qgis_project-0.3.10.tar.gz.

File metadata

  • Download URL: qgis_project-0.3.10.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qgis_project-0.3.10.tar.gz
Algorithm Hash digest
SHA256 ba1732500d6503ed1b4f758cdd2e9706d93bd7332dd8eb1e6ae0562295abf5b4
MD5 5c1b43e603e09b74378c22ee446b468e
BLAKE2b-256 6f4ffd13b2fe9aa9bcae872d22a3cb115c6a16d828cb5d7ae66c80357a0a4ab9

See more details on using hashes here.

Provenance

The following attestation bundles were made for qgis_project-0.3.10.tar.gz:

Publisher: publish.yml on ColinMoldenhauer/qgis-project

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qgis_project-0.3.10-py3-none-any.whl.

File metadata

  • Download URL: qgis_project-0.3.10-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qgis_project-0.3.10-py3-none-any.whl
Algorithm Hash digest
SHA256 27d0b9228ae74adb03c97287cd7229972a93d18ab8ae3d57495c8e576a5886bf
MD5 507b9d8b567f8affce71b91c91641228
BLAKE2b-256 07b2586be2c9debae09c5c2c823829b8aa4544f18d1a39dc8d2bdfaee584e2b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for qgis_project-0.3.10-py3-none-any.whl:

Publisher: publish.yml on ColinMoldenhauer/qgis-project

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page