From 5f80de49c4a00416591054180bf809a12a76d686 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 07 十一月 2024 16:40:53 +0800
Subject: [PATCH] 1

---
 ExportMap/Sources/MoonExp.py |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/ExportMap/Sources/MoonExp.py b/ExportMap/Sources/MoonExp.py
index 9e19c50..363912f 100644
--- a/ExportMap/Sources/MoonExp.py
+++ b/ExportMap/Sources/MoonExp.py
@@ -97,6 +97,21 @@
         prj.addMapLayer(layer)
 
 
+# 鑾峰彇姣斾緥灏�
+def get_scale(scale):
+    # scale = '1:' + str(math.ceil(map.scale() / 100) * 100)
+    if scale > 10000:
+        return "1:" + str(math.ceil(map.scale() / 10000)) + "涓�"
+    elif scale > 1000:
+        return "1:" + str(math.ceil(map.scale() / 1000)) + "鍗�"
+    elif scale > 100:
+        return "1:" + str(math.ceil(map.scale() / 100) * 100)
+    elif scale > 10:
+        return "1:" + str(math.ceil(map.scale() / 10) * 10)
+    else:
+        return "1:" + str(math.ceil(scale))
+
+
 # 鍒濆鍖�
 # QgsApplication.setPrefixPath(r"E:/terrait/TianJin/LFServer/QGIS/", True)
 qgs = QgsApplication([], False)
@@ -124,24 +139,17 @@
 # map = layout.itemById(r'鍦板浘')
 map = layout.referenceMap()
 map.zoomToExtent(map.extent())
-scale = '1:' + str(math.ceil(map.scale() / 100) * 100)
+scale = get_scale(map.scale())
 print(scale)
-
-# template_content = template_content.replace('1锛�25涓�', scale)
-# doc.setContent(template_content)
-# layout.loadFromTemplate(doc, QgsReadWriteContext(), True)
-# map = layout.referenceMap()
-# map.zoomToExtent(map.extent())
 
 size = map.sizeWithUnits()
 print('size: ' + str(size.width()) + " * " + str(size.height()) + " mm")
-if size.width() > 280 or size.height() > 174:
-    map.attemptResize(QgsLayoutSize(280, 174, QgsUnitTypes.LayoutMillimeters))
+if size.width() > 233 or size.height() > 174:
+    map.attemptResize(QgsLayoutSize(233, 174, QgsUnitTypes.LayoutMillimeters))
     print('size: ' + str(map.sizeWithUnits().width()) + " * " + str(map.sizeWithUnits().height()) + " mm")
 
 # 璁剧疆鍥惧眰
-# "闃�瀹�", "绔欏満", "绠¢亾涓績绾�", "鐭㈤噺娉ㄨ", "鐭㈤噺鍥�", "楂樺痉褰卞儚娉ㄨ", "楂樺痉褰卞儚", "褰卞儚娉ㄨ", "褰卞儚鍥�"
-# showLayers = ["闃�瀹�", "绠¢亾涓績绾�", "鐭㈤噺娉ㄨ", "鐭㈤噺鍥�"]
+# showLayers = ["闃�瀹�", "绔欏満", "绠¢亾涓績绾�", "鐭㈤噺娉ㄨ", "鐭㈤噺鍥�", "楂樺痉褰卞儚娉ㄨ", "楂樺痉褰卞儚", "褰卞儚娉ㄨ", "褰卞儚鍥�"]
 showLayers = layout.customProperty("layers").split(',')
 root = project.layerTreeRoot()
 
@@ -152,8 +160,9 @@
 # sm = layout.itemById(r'璇存槑')
 '''table = layout.multiFrames()[0]
 contents = table.tableContents()
-contents[1][1] = scale
-table.refreshAttributes()
+# contents[0][1] = scale
+contents[1][1].setContent(scale)
+table.setTableContents(contents)
 table.refresh()'''
 
 # collection = layout.pageCollection()

--
Gitblit v1.9.3