管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-08 2888add57ea5ed336cb0ac1d66babda8893f29d3
1
已修改1个文件
7 ■■■■■ 文件已修改
QGIS/render.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/render.py
@@ -50,10 +50,12 @@
            node.setItemVisibilityChecked(flag)
# 初始化
# QgsApplication.setPrefixPath(r"E:/terrait/TianJin/LFServer/QGIS/", True)
qgs = QgsApplication([], True)
qgs.initQgis()
# 加载工程
args = getArgs()
project = QgsProject.instance()
# project.read(r'Test.qgz')
@@ -64,6 +66,7 @@
layout = QgsLayout(project)
# layout.initializeDefaults()
# 加载模板
# with open(r'Test.qpt', 'r', encoding='utf-8') as f:
with open(args.qpt, 'r', encoding='utf-8') as f:
    template_content = f.read()
@@ -75,6 +78,7 @@
map = layout.referenceMap()
print('1:' + str(math.ceil(map.scale())))
# 设置图层
# "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"
# showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"]
showLayers = layout.customProperty("layers").split(',')
@@ -82,12 +86,15 @@
# setLayersValid(project, showLayers)
setItemVisibility(root, showLayers)
# 刷新
layout.refresh()
map.refresh()
# 导出
exporter = QgsLayoutExporter(layout)
# img_path = os.path.join(r"E:/terrait/TianJin/LFServer/QGIS", "render.png")
img_path = layout.customProperty("imgPath")
exporter.exportToImage(img_path, QgsLayoutExporter.ImageExportSettings())
# 退出
qgs.exitQgis()