管道基础大数据平台系统开发-【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()
# 加载工程
@@ -82,11 +82,21 @@
# map = layout.itemById(r'地图')
map = layout.referenceMap()
map.zoomToExtent(map.extent())
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())
print('1:' + str(math.ceil(map.scale())))
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))
    print('size: ' + str(map.sizeWithUnits().width()) + " * " + str(map.sizeWithUnits().height()) + " mm")
# 设置图层
# "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"
@@ -96,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()
# 导出