Estoy tratando de llegar a un fragmento de código que me permite imprimir mapas PDF con la API de PYQGIS utilizando un espacio de trabajo y una plantilla.
Este código hace el trabajo, pero arroja un error que me impide alinear mapas consecutivos para que se produzcan.
sys.path.append('/Applications/QGIS.app/Contents/Resources/python')
import os
from qgis.core import (
QgsProject, QgsComposition, QgsApplication, QgsProviderRegistry)
from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge
from PyQt4.QtCore import QFileInfo
from PyQt4.QtXml import QDomDocument
from qgis.core import *
def make_pdf():
project_path = 'project.qgs'
template_path = 'template.qpt'
gui_flag = True
QgsApplication.setPrefixPath("/Applications/QGIS.app/Contents/Resources/python", True)
app = QgsApplication(sys.argv, gui_flag)
app.setPrefixPath("/Applications/QGIS.app/Contents/MacOS", True)
app.initQgis()
canvas = QgsMapCanvas()
QgsProject.instance().read(QFileInfo(project_path))
bridge = QgsLayerTreeMapCanvasBridge(
QgsProject.instance().layerTreeRoot(), canvas)
bridge.setCanvasLayers()
template_file = file(template_path)
template_content = template_file.read()
template_file.close()
document = QDomDocument()
document.setContent(template_content)
composition = QgsComposition(canvas.mapSettings())
composition.loadFromTemplate(document, {})
composition.refreshItems()
composition.exportAsPDF('output.pdf')
QgsProject.instance().clear()
La salida es:
QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:
QSqlQuery::prepare: database not open
ERROR: Opening of authentication db FAILED
WARNING: Auth db query exec() FAILED
Loading a file that was saved with an older version of qgis (saved in 2.12.1-Lyon, loaded in 2.16.3). Problems may occur.
QObject::startTimer: QTimer can only be used with threads started with QThread
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Ese error de SIGSERV al final parece bastante desagradable, pero no estoy ni cerca de entender lo que sucede cuando busco eso en Google.