carey136 / Standalone-Export-Atlas-QGIS3

Standalone Script to Export Atlas to PDF/images
GNU General Public License v3.0
10 stars 0 forks source link

Standalone-Export-Atlas-QGIS3

This code exports a chosen atlas print layout from a QGS file using a stand-alone python script. The output can either be a multi-page PDF or a set of images.

Version information/requirements:

To run the script in command line:

1. Open AtlasExport.py in a syntax highlighting text editor

2. Change the 8 variables as required and save the file:

myProject = "c:your\\project\\location.qgs"
layoutName = "atlas_name"
coverageLayer = "Layer_name"
atlasFilter = '"column" = "value"'
outputFormat = "pdf"
outputFolder = "c:your\project\folder"
outputName = "query producing unique value"
pdfName = "Export"

Note: \ is an escape character in python:

* When quoting file paths, use double backslashes: c:your\\path\\here

* When using " or ' as part of a query/filter, escape these characters with a backslash: '\"FeatureType\" = \'building\''

myProject (override with flag -P "project path")

The project file path in the following format: For example "c:your\\project\\location.qgs"

layoutName (override with flag -L "atlas_name")

The name of layout set up for atlas exporting: For example "Atlas_A4"

coverageLayer (override with flag -C "layer_name")

The name of the coverage layer used in the project file. This is derived from the layer name as displayed in the map's table of contents (and can contain spaces). Wrap the name in quotation marks: for example "Rights of Way"

atlasFilter (override with flag -F "layer_name" "operator" "values")

The script will now output the images of PDFs to the location noted in the script. If you encounter any errors, the explicit reason will be displayed in command line allowing you to troubleshoot.

Flags / Overrides examples

These can be used to change many input and output parameters without modifying the code. Below is an exmaples in action: C:\OSGeo4W64\bin\python-qgis.bat C:\Temp\py\pyrow2.py -F "parishcode" "=" "207" -O image -D "C:\Users\Guy\Desktop"

For use while in commandline, use --help fpr more info

To run as a batch file