-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code2.py
49 lines (42 loc) · 1.07 KB
/
Code2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from qgis.core import (
QgsGeometry,
QgsMapSettings,
QgsPrintLayout,
QgsMapSettings,
QgsMapRendererParallelJob,
QgsLayoutItemLabel,
QgsLayoutItemLegend,
QgsLayoutItemMap,
QgsLayoutItemPolygon,
QgsLayoutItemScaleBar,
QgsLayoutExporter,
QgsLayoutItem,
QgsLayoutPoint,
QgsLayoutSize,
QgsUnitTypes,
QgsProject,
QgsFillSymbol,
)
from qgis.PyQt.QtGui import (
QPolygonF,
QColor,
)
from qgis.PyQt.QtCore import (
QPointF,
QRectF,
QSize,
)
project = QgsProject.instance()
layout = QgsPrintLayout(project)
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
# Provide an extent to render
map.zoomToExtent(iface.mapCanvas().extent())
layout.addLayoutItem(map)
base_path = os.path.join(QgsProject.instance().homePath())
pdf_path = os.path.join(base_path, "output.png")
exporter = QgsLayoutExporter(layout)
exporter.exportToImage(pdf_path, QgsLayoutExporter.ImageExportSettings())
layout.setName("MyLayout")
project.layoutManager().addLayout(layout)