-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontour.py
42 lines (33 loc) · 1.12 KB
/
contour.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
#!/usr/bin/env python3
from sys import argv
if not len(argv) == 6:
print("contour.py: Error: contour.py <GPKG Input File> <PNG Output File> <FG colour> <BG colour> <Line Thickness>")
print("Colors are given in hex RGB or RGBA values")
exit(1)
from qgis.core import (
QgsApplication,
QgsMapRendererParallelJob,
QgsMapSettings,
QgsProject,
QgsVectorLayer,
)
from qgis.PyQt.QtGui import QColor
from qgis.PyQt.QtCore import QSize
QgsApplication.setPrefixPath('/usr', True)
path_to_gpkg = argv[1]
path_to_png = argv[2]
gpkg_layer = path_to_gpkg + "|layername=Contour"
vlayer = QgsVectorLayer(gpkg_layer, "Contour", "ogr")
QgsProject.instance().addMapLayer(vlayer)
vlayer.renderer().symbol().setColor(QColor(argv[3]))
vlayer.renderer().symbol().setWidth(float(argv[5]))
settings = QgsMapSettings()
settings.setLayers([vlayer])
settings.setBackgroundColor(QColor(argv[4]))
settings.setOutputSize(QSize(1000, 1000))
settings.setExtent(vlayer.extent())
settings.setOuputDpi = 100
render = QgsMapRendererParallelJob(settings)
render.start()
render.waitForFinished()
render.renderedImage().save(path_to_png, "png")