I am trying to generate an atlas with python in qgis 3.0. I have :
projectInstance= QgsProject.instance()
projectLayoutManager = projectInstance.layoutManager()
for comp in projectLayoutManager.printLayouts():
if comp.atlas().enabled():
comp.atlas().beginRender()
nbobj = comp.atlas().updateFeatures()
comp.atlas().first()
for i in range(0, comp.atlas().count ()):
comp.atlas().refreshCurrentFeature ()
exporter = QgsLayoutExporter(comp.atlas().layout () )
pdf_settings = exporter.ImageExportSettings () #dpi?
exporter.exportToImage (, pdf_settings)
comp.atlas().endRender()
But I would like the filename to have some attributes of the atlas feature.
How do I get the value of the attribute?
Answer
You can simplify this script considerably in QGIS 3.0:
projectInstance= QgsProject.instance()
projectLayoutManager = projectInstance.layoutManager()
image_settings = exporter.ImageExportSettings()
image_settings.dpi = 300 # or whatever you want
for comp in projectLayoutManager.printLayouts():
if comp.atlas().enabled():
result, error = QgsLayoutExporter.exportToImage(comp.atlas(),
baseFilePath='c:/temp/my_atlas', extension='.png', settings=image_settings)
if not result == QgsLayoutExporter.Success:
print(error)
To control the generated filenames, you need to set an expression for the atlas filenames, e.g.:
comp.atlas().setFilenameExpression('"some_attribute" || '_export' )
No comments:
Post a Comment