| | |
| | | |
| | | # 初始化 |
| | | # QgsApplication.setPrefixPath(r"E:/terrait/TianJin/LFServer/QGIS/", True) |
| | | qgs = QgsApplication([], True) |
| | | qgs = QgsApplication([], False) |
| | | qgs.initQgis() |
| | | |
| | | # 加载工程 |
| | |
| | | # 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") |
| | | 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") |
| | | |
| | | # 设置图层 |
| | | # "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图" |
| | |
| | | # set_layers_valid(project, showLayers) |
| | | set_item_visibility(root, showLayers) |
| | | |
| | | collection = layout.pageCollection() |
| | | page = collection.page(0) |
| | | page.refreshItemSize() |
| | | # 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() |
| | | |
| | | # 导出 |