[Qgis-developer] Set Composer scale with pyqgis

roy roy royroge at outlook.com
Mon Jul 11 00:55:28 PDT 2016


Hi,

still the only way i found to set the composer
map is using

zoomToExtent(canvas.extent())

but not able to set a custom defined scale,
any hint to find some documentation
or some way to set the composer scale using pyQGIS?
thanks again

Il 07/07/2016 12:59, roy roy ha scritto:
> Hi, I'm trying to print a map using pyqgis and an existing template:
>
> # i already loaded a layer and zoomed to the layer:
>
> qgis.utils.iface.zoomToActiveLayer()
>
> # now i need to zoom to a "precise" scale
> canvas = qgis.utils.iface.mapCanvas()
> canvas.zoomScale(2500) # this works for the canvas not in the composer
>
> # load the template
> template_file = file(template_path)
> template_content = template_file.read()
> template_file.close()
> document = QDomDocument()
> document.setContent(template_content)
> composition = QgsComposition(canvas.mapSettings())
> composition.loadFromTemplate(document)
> map_item = composition.getComposerItemById('map')
> map_item.setMapCanvas(canvas)
>
> # at this point i need to set the extent to fit the layer
> map_item.zoomToExtent(canvas.extent()) # this will not be in scale 2500
> of course
>
> now i need the scale to be say 2500 but i cannot find how to
> set the value
>
> thanks for any help, Roy
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the Qgis-developer mailing list