Extent problem in PyQgis

المشرف العام

Administrator
طاقم الإدارة
I'm trying to set the extent of a square feature to the canvas, that works in Qgis, but when i print the canvas into PDF, it gimme always some empty area, below the screenshot of Qgis canvas having feature extent:



below the resulting PDF having empty spaces:



below pyqgis code used to get these results:

from qgis.core import * mr=iface.mapCanvas().mapRenderer()composition = QgsComposition(mr)composition.setPaperSize(220, 220)composerMap = QgsComposerMap(composition, 0,0, composition.paperWidth(), composition .paperHeight())composition.addItem(composerMap)id=3020vlayer= QgsMapLayerRegistry.instance().mapLayers().values()[0] expr = QgsExpression("\"id\"="+str(id))it = vlayer.getFeatures(QgsFeatureRequest(expr))ids = [i for i in it] bb = ids[0].geometry().boundingBox()iface.mapCanvas().setExtent(bb)iface.mapCanvas().refresh()composition.refreshItems()composition.exportAsPDF('test.pdf')

أكثر...
 
أعلى