Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
/ pyqgis_wrappers Public archive

common functions to be used in pyqgis and python qgis plugins

License

Notifications You must be signed in to change notification settings

qgis/pyqgis_wrappers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

This project is archived and stays only for reference

pyqgis_wrappers

Common functions to be used in pyqgis and python qgis plugins

NOTE: Just a sandbox for now. Don't consider the API stable.

These are wrappers around common pyqgis idioms that allows for faster development and hopefully removes some of the (sometimes) ugly C/C++ based API (read: not Python-ish)

The current plan is to flesh out ideas here and then mirgate them to core QGIS as they become stable or well designed.

What can it do so far?

Opening a project

with qgisapp(sys.argv, guienabled=True) as app:
    canvas = QgsMapCanvas()
    with open_project(pfile, canvas=canvas) as project:
        print project

or without the with block

with qgisapp(sys.argv, guienabled=True) as app:
    canvas = QgsMapCanvas()
    project = open_project(pfile, canvas=canvas)
    print project

Rendering a composer template from a file.

import sys
from qgis.gui import QgsMapCanvas
from wrappers import render_template, map_layers, open_project, qgisapp

pfile = r"project.qgs"
template = r"template.qpt"

with qgisapp(sys.argv, guienabled=True) as app:
    canvas = QgsMapCanvas()
    with open_project(pfile, canvas=canvas) as project:
        settings = project.map_settings
        render_template(template, settings, canvas, r"out.pdf")

or without the with block

with qgisapp(sys.argv, guienabled=True) as app:
    canvas = QgsMapCanvas()
    project = open_project(pfile, canvas=canvas)
    settings = project.map_settings
    render_template(template, settings, canvas, r"out.pdf")
    project.close()

Listing loaded layers

from wrappers import map_layers
layers = map_layers()
mylayer = map_layers(name='mylayer')

filter by regex

from wrappers import map_layers
for layer in map_layers(".*Bound.*"):
    print layer.name()

About

common functions to be used in pyqgis and python qgis plugins

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages