Ryan Rueger

ryan@rueg.re / picture / key / home
aboutsummaryrefslogtreecommitdiff
path: root/contour.py
diff options
context:
space:
mode:
authorrrueger <rrueger.github@velleto.com>2021-08-19 19:55:57 +0200
committerrrueger <rrueger.github@velleto.com>2021-08-19 19:55:57 +0200
commit501e376b507f9dfbe6ffc5b314eaff17a2958eb7 (patch)
treec14e2db26fa8025694d8bdff959c9cee2e08698b /contour.py
downloadcontours-501e376b507f9dfbe6ffc5b314eaff17a2958eb7.tar.gz
contours-501e376b507f9dfbe6ffc5b314eaff17a2958eb7.tar.bz2
contours-501e376b507f9dfbe6ffc5b314eaff17a2958eb7.zip
Initial commit
Diffstat (limited to 'contour.py')
-rw-r--r--contour.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/contour.py b/contour.py
new file mode 100644
index 0000000..48fd2a5
--- /dev/null
+++ b/contour.py
@@ -0,0 +1,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")