I'm trying map rendering with stand alone script, so I have small script which works fine in python console provided QGIS, however when I run same code in stand-alone script it executes without error, but output is not produced.
Here is my standalone script:
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtXml import *
QgsApplication.setPrefixPathddd("C:\Program Files (x86)\QGIS Valmiera", True)
QgsApplication.initQgis()
mapinstance = QgsMapLayerRegistry.instance()
mapinstance.removeAllMapLayers()
layer = QgsVectorLayer("F:\scripts\map\wb.shp", "test", "ogr")
if layer.isValid():
print "shplayer succesfully loaded - adding to mapinstance"
mapinstance.addMapLayer(layer)
else:
print "shplayer failed to load!"
print mapinstance.mapLayers()
# create image
img = QImage(QSize(800,600), QImage.Format_ARGB32_Premultiplied)
# set image background color
color = QColor(255,255,255)
img.fill(color.rgb())
# create painter
p = QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
render = QgsMapRenderer()
# set layer set
lst = [ layer.id() ] # add ID of every layer
render.setLayerSet(lst)
# set extent
rect = QgsRectangle(render.fullExtent())
#rect.scale(1.39800703)
rect.scale(1.1)
render.setExtent(rect)
# set output size
render.setOutputSize(img.size(), img.logicalDpiX())
# do the rendering
render.render(p)
p.end()
# save image
img.save('F:\scripts\out.png',"png")
QgsApplication.exitQgis()
No comments:
Post a Comment