管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-07 8d7a67ab1d635cb954337d8a767878ae526dd3dc
ExportMap/Sources/render.py
@@ -58,7 +58,7 @@
# 初始化
# QgsApplication.setPrefixPath(r"E:/terrait/TianJin/LFServer/QGIS/", True)
qgs = QgsApplication([], True)
qgs = QgsApplication([], False)
qgs.initQgis()
# 加载工程
@@ -83,7 +83,14 @@
# map = layout.itemById(r'地图')
map = layout.referenceMap()
map.zoomToExtent(map.extent())
print('1:' + str(math.ceil(map.scale())))
scale = '1:' + str(math.ceil(map.scale() / 100) * 100)
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")
@@ -99,13 +106,23 @@
# set_layers_valid(project, showLayers)
set_item_visibility(root, showLayers)
# sm = layout.itemById(r'说明')
table = layout.multiFrames()[0]
contents = table.tableContents()
# contents[1][1] = str(scale)
contents[1][1].setContent(scale)
# table.refreshAttributes()
table.setTableContents(contents)
table.refresh()
# collection = layout.pageCollection()
# page = collection.page(0)
# page.refreshItemSize()
# 刷新
map.refresh()
layout.updateBounds()
# layout.updateBounds()
layout.renderContext()
layout.refresh()
# 导出