<div dir="ltr">Hi Martin, et al.,<br clear="all"><div><div><br></div><div>Maybe I'm missing something elemental here, but I can't seem to find a simple way to apply my built-up QgsMapSettings to QgsMapCanvas or QgsMapRenderer, initiate a render from Python, then save into image on disk.<br>
<br></div><div>This is what I would like to do (for simple screen-res renders):<br><br></div><div>cnv = iface.mapCanvas()</div><div>ms = cnv.mapSettings()  <-- or create fresh: ms = QgsMapSettings()<br></div><div>(manipulate map settings)<br>
</div><div>cnv.applyMapSettings(ms)  <-- shouldn't this be possible?<br></div><div>cnv.refresh()  <-- since cnv.map().render() is stubbed now<br>cnv.saveAsImage(my_imgpath)<br><br></div><div>This is functioning (for creating unit test control images), but seems excessive:<br>
<br>ms = my_map_settings<br>pal = QgsPalLabeling()<br>pal.init(ms)  <-- is this necessary?<br>r = QgsMapRenderer()<br>r.setLabelingEngine(pal)<br><br></div><div># couldn't the next lines be covered by a r.applyMapSettings(ms) function?<br>
</div><div>r.setOutputSize(ms.outputSize(), ms.outputDpi())<br>r.setMapUnits(ms.mapUnits())<br>r.setExtent(ms.extent())<br>r.setProjectionsEnabled(ms.hasCrsTransformEnabled())<br>r.setDestinationCrs(ms.destinationCrs())<br>
r.setLayerSet(ms.layers())<br><br>image = QImage(ms.outputSize(), QImage.Format_ARGB32)<br>image.fill(ms.backgroundColor().rgb())<br>image.setDotsPerMeterX(ms.outputDpi() / 25.4 * 1000)<br>image.setDotsPerMeterY(ms.outputDpi() / 25.4 * 1000)<br>
<br>p = QPainter(image)<br>r.render(p)<br>p.end()<br>image.save(my_imgpath, 'png'):<br></div><div><br><br></div><div>This is already convenient in QgsComposition, using QgsComposition( const QgsMapSettings& mapSettings ), then just render the page.<br>
<br></div><div>Any ideas on the best approach here?<br></div><div><br></div><div>Regards,<br></div><div><br>Larry</div>
</div></div>