[Qgis-user] PyQgis - PostGIS layers won't show in export to PDF (layout)
Baker, Matthew
MATTHEW_BAKER at dpsk12.org
Tue Aug 17 13:14:12 PDT 2021
Hi all,
When using PyQGIS with Python 3.8 I can't seem to get the PostGIS layers of a QGIS layout to export to PDF while the local / shapefile layers will.
The manual export to PDF from the QGIS Layout window will export the PostGIS layers just fine along with the SHP layers.
From the code below, can anyone spot what I might be missing?
(Running QGIS 3.18 on Linux Mint 20 with Python 3.8)
Thank you, and let me know if more info is needed!
(BEGIN CODE)
#!/usr/bin/env python3
import os
from qgis.core import (
#layout and general
QgsProject, QgsLayoutExporter, QgsApplication
)
QgsApplication.setPrefixPath("/usr", True)
gui_flag = False
app = QgsApplication([], gui_flag)
app.initQgis()
project_path = os.getcwd() + '/rec_centers.qgz'
project_instance = QgsProject.instance()
project_instance.setFileName(project_path)
project_instance.read()
#print layer names in layout (not used anywhere else):
names = [layer.name() for layer in QgsProject.instance().mapLayers().values()]
print ('Layers in project: ', names)
#layout stuff
manager = QgsProject.instance().layoutManager()
layout = manager.layoutByName("test_layout") # name of the layout
#export stuff
exporter = QgsLayoutExporter(layout)
exporter.exportToPdf(project_instance.absolutePath() + "/output/layout.pdf",
QgsLayoutExporter.PdfExportSettings())
app.exitQgis()
(END CODE)
-m
--
MATTHEW BAKER
Spatial Information Manager
Denver Public Schools
Department of Enrollment and Campus Planning
1860 Lincoln St., Denver, CO 80203 | 11th Floor
720-423-3419 | matthew_baker at dpsk12.org | planning.dpsk12.org
Students First . Integrity . Equity . Collaboration . Accountability . Fun .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210817/158322d1/attachment.html>
More information about the Qgis-user
mailing list