| | |
| | | import os |
| | | import math |
| | | from qgis.core import * |
| | | from qgis.gui import * |
| | | from qgis.PyQt.QtGui import * |
| | |
| | | |
| | | # layout = QgsPrintLayout(project) |
| | | layout = QgsLayout(project) |
| | | layout.initializeDefaults() |
| | | # layout.initializeDefaults() |
| | | |
| | | with open(r"E:/terrait/TianJin/LFServer/QGIS/Template.qpt", 'r', encoding='utf-8') as f: |
| | | template_content = f.read() |
| | | doc = QDomDocument() |
| | | doc.setContent(template_content) |
| | | layout.loadFromTemplate(doc, QgsReadWriteContext(), False) |
| | | layout.loadFromTemplate(doc, QgsReadWriteContext(), True) |
| | | |
| | | # map = QgsLayoutItemMap(layout) |
| | | # map.zoomToExtent(layers[0].extent()) |
| | | # layout.addItem(map) |
| | | |
| | | # collection = layout.pageCollection() |
| | | # page = QgsLayoutItemPage(layout) |
| | | # page.setPageSize('A4') |
| | | # collection.addPage(page) |
| | | |
| | | # layoutView = QgsLayoutView() |
| | | # layoutView.setPreviewModeEnabled(True) |
| | | # layoutView.setContentsMargins(0, 0, 0, 0) |
| | | # layoutView.setCurrentLayout(layout) |
| | | map = layout.itemById(r'地图') |
| | | print(math.ceil(map.scale())) |
| | | |
| | | exporter = QgsLayoutExporter(layout) |
| | | img_path = os.path.join(r"E:/terrait/TianJin/LFServer/QGIS", "render.png") |