Re: [Qgis-developer] Set Composer scale with pyqgis
Hi, for some reason my email client did not download or received the answer to my question, sent by "boesiii", that i find righ now browsing the mailing list archive. So, using map_item.setNewScale(canvas.scale()) i can surely set the scale for the map composer thank you Boesiii and sorry to the list for my second message. Il 11/07/2016 09:55, roy roy ha scritto: > 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@lists.osgeo.org >> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer >> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer > ___ > Qgis-developer mailing list > Qgis-developer@lists.osgeo.org > List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Set Composer scale with pyqgis
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@lists.osgeo.org > List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Set Composer scale with pyqgis
Try: map_item.setNewScale(canvas.scale()) -- View this message in context: http://osgeo-org.1560.x6.nabble.com/Set-Composer-scale-with-pyqgis-tp5275120p5275129.html Sent from the Quantum GIS - Developer mailing list archive at Nabble.com. ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
[Qgis-developer] Set Composer scale with pyqgis
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@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer