| | |
| | | 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') |
| | |
| | | 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() |
| | |
| | | map = layout.referenceMap() |
| | | print('1:' + str(math.ceil(map.scale()))) |
| | | |
| | | # 设置图层 |
| | | # "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图" |
| | | # showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"] |
| | | showLayers = layout.customProperty("layers").split(',') |
| | |
| | | # 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() |