From 839871788f5cfde328a7049a174f809c4b9c0b7e Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 16 十一月 2023 17:11:35 +0800 Subject: [PATCH] 修改月球出图模板 --- 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..f2eee56 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,14 +139,8 @@ # 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") @@ -140,8 +149,7 @@ print('size: ' + str(map.sizeWithUnits().width()) + " * " + str(map.sizeWithUnits().height()) + " mm") # 璁剧疆鍥惧眰 -# "闃�瀹�", "绔欏満", "绠¢亾涓績绾�", "鐭㈤噺娉ㄨ", "鐭㈤噺鍥�", "楂樺痉褰卞儚娉ㄨ", "楂樺痉褰卞儚", "褰卞儚娉ㄨ", "褰卞儚鍥�" -# showLayers = ["闃�瀹�", "绠¢亾涓績绾�", "鐭㈤噺娉ㄨ", "鐭㈤噺鍥�"] +# showLayers = ["闃�瀹�", "绔欏満", "绠¢亾涓績绾�", "鐭㈤噺娉ㄨ", "鐭㈤噺鍥�", "楂樺痉褰卞儚娉ㄨ", "楂樺痉褰卞儚", "褰卞儚娉ㄨ", "褰卞儚鍥�"] showLayers = layout.customProperty("layers").split(',') root = project.layerTreeRoot() @@ -150,11 +158,12 @@ # add_map_layer(project, layout) # sm = layout.itemById(r'璇存槑') -'''table = layout.multiFrames()[0] +table = layout.multiFrames()[0] contents = table.tableContents() -contents[1][1] = scale -table.refreshAttributes() -table.refresh()''' +# contents[0][1] = scale +contents[1][1].setContent(scale) +table.setTableContents(contents) +table.refresh() # collection = layout.pageCollection() # page = collection.page(0) -- Gitblit v1.9.3