I am writing an QGIS Python processing script, the result of this script is a formatted PDF. In one of the steps, I need to set map canvas extent to my shapefile extent, but it is not working.
What is the difference on this context from a standalone script, for instance?
This is how I am trying to set map canvas extent:
# Reference to map Canvas
canvas = QgsMapCanvas()
# allow anti aliasing
canvas.enableAntiAliasing(flag=True)
# canvas color
canvas.setCanvasColor(Qt.white)
# canvas extension
canvas.setExtent(fieldlayer.extent())
# set canvas layer
canvas.setLayers([fieldlayer])
In this context, I can't start qgs application through the usual command lines because the script would crash:
# Start qgs
os.environ["QT_QPA_PLATFORM"] = "offscreen"
QgsApplication.setPrefixPath("/usr", True)
qgs = QgsApplication([], False)
qgs.initQgis()
### qgs manipulation here ###
# Exit qgs
qgs.exitQgis()
The whole script can be found here: