From d8ce4e1d7fe96410a5fab96f46649280024ab2d9 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 07 十一月 2022 16:35:49 +0800
Subject: [PATCH] 1

---
 QGIS/render.py |   25 ++++---------------------
 1 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/QGIS/render.py b/QGIS/render.py
index 68ab339..5612bc9 100644
--- a/QGIS/render.py
+++ b/QGIS/render.py
@@ -1,4 +1,5 @@
 import os
+import math
 from qgis.core import *
 from qgis.gui import *
 from qgis.PyQt.QtGui import *
@@ -19,7 +20,7 @@
 
 # layout = QgsPrintLayout(project)
 layout = QgsLayout(project)
-layout.initializeDefaults()
+# layout.initializeDefaults()
 
 with open(r"E:/terrait/TianJin/LFServer/QGIS/Template.qpt", 'r', encoding='utf-8') as f:
     template_content = f.read()
@@ -27,26 +28,8 @@
 doc.setContent(template_content)
 layout.loadFromTemplate(doc, QgsReadWriteContext(), True)
 
-# map = QgsLayoutItemMap(layout)
-# # map.zoomToExtent(layers[0].extent())
-# layout.addItem(map)
-
-collection = layout.pageCollection()
-collection.deletePage(0)
-page = QgsLayoutItemPage(layout)
-page.setPageSize('A5', True)
-collection.addPage(page)
-collection.redraw()
-
-# collection = layout.pageCollection()
-# page = collection.page(0)
-# # QgsUnitTypes.LayoutCentimeters
-# size = QgsLayoutSize(2480, 1748, QgsUnitTypes.LayoutPixels)
-# page.setPageSize('A3', True)
-
-# imgSetting = QgsLayoutExporter.ImageExportSettings()
-# imgSetting.imageSize.width = 4096
-# imgSetting.imageSize.heigth = 3507
+map = layout.itemById(r'鍦板浘')
+print(math.ceil(map.scale()))
 
 exporter = QgsLayoutExporter(layout)
 img_path = os.path.join(r"E:/terrait/TianJin/LFServer/QGIS", "render.png")

--
Gitblit v1.9.3