[QGIS-Developer] QgsPrintLayout Setup from PyQGIS 3

Brian Libgober libgober at gmail.com
Tue Mar 27 06:55:30 PDT 2018


I am interested in making reproducible PDF figures in QGIS3, and therefore
want to work from the console/PyQGIS. Thanks to some previous helpful
advice here
<https://gis.stackexchange.com/questions/274199/qgis-3-pdf-output-with-python>,
the problem is successfully reduced to setting up the QgsPrintLayout. I am
not sure how to do this, below is my best attempt so far:

#setup the background classes for managing the project
canvas =iface.mapCanvas()
manager = project.layoutManager()#new layout
layout = QgsPrintLayout(project)
layout.initializeDefaults()
layout.setName('console')
itemMap = QgsLayoutItemMap(layout)
itemMap.setExtent(canvas.extent())
layout.addLayoutItem(itemMap)#add the layout to the manager
manager.addLayout(layout)

The "console" layout is successfully added to QGIS 3 and I can open it to
see if the content is satisfactory. The map does not render and its extent
is nan,nan,nan,nan. How do I setup the extent and size of the map object in
the layout?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180327/9b3395ac/attachment-0001.html>


More information about the QGIS-Developer mailing list