学习到渲染(QgsMapRendererJob
),按照教程所讲总是输出不了图像,看了一下qgis的测试源码,发现少了一句话,加上后就可以输出了!
from qgis.core import * from qgis.gui import * from qgis.PyQt.QtCore import * from qgis.PyQt.QtWidgets import * from qgis.PyQt.QtGui import * if __name__ == "__main__": vLayer = QgsVectorLayer("E:\qgis-and-tools\河北省\河北省.shp", "Hebei", "ogr") options = QgsMapSettings() options.setLayers([vLayer]) options.setBackgroundColor(QColor(255, 255, 255)) options.setOutputSize(QSize(800, 600)) options.setExtent(vLayer.extent()) renderer = QgsMapRendererParallelJob(options) def finished(): print("img") img = renderer.renderedImage() print("begin save") img.save("E:\qgis-and-tools\河北省\hebei.png") print("save") renderer.finished.connect(finished) print("render connect") renderer.start() ##需要加上这一句话才能输出图片 renderer.waitForFinished()