<div dir="ltr">Hi Martin,<br><div class="gmail_extra"><br></div><div class="gmail_extra">Any suggestions on the following?<br clear="all"></div><div class="gmail_extra"><div><br>Larry<br></div><br><div class="gmail_quote">
On Tue, Mar 4, 2014 at 2:39 PM, Larry Shaffer <span dir="ltr"><<a href="mailto:larrys@dakotacarto.com" target="_blank">larrys@dakotacarto.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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>
</blockquote></div><br></div></div>