Skip to content

Commit 4fbea38

Browse files
Trashmonkm-kuhn
authored andcommitted
Added transparency to areas with no vector data.
Originally the background colour defaulted to white with no transparency for areas without vector data. I have added an alpha channel to the geotiff and set it zero (full transparency) for areas with no vector data. This could be optional, in case the user wants a solid background.
1 parent 9fe8729 commit 4fbea38

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

python/plugins/processing/algs/qgis/Rasterize.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
2323

24-
from qgis.PyQt.QtGui import QImage, QPainter
24+
from qgis.PyQt.QtGui import QImage, QPainter, QColor
2525
from qgis.PyQt.QtCore import QSize
2626
from qgis.core import (
2727
QgsMapSettings,
@@ -228,7 +228,7 @@ def __init__(self, map_theme, layer, extent, tile_size, mupp, output,
228228
xsize = self.x_tile_count * tile_size
229229
ysize = self.y_tile_count * tile_size
230230

231-
self.dataset = driver.Create(output, xsize, ysize, 3) # 3 bands
231+
self.dataset = driver.Create(output, xsize, ysize, 4) # 4 bands
232232
self.dataset.SetProjection(str(crs.toWkt()))
233233
self.dataset.SetGeoTransform(
234234
[extent.xMinimum(), mupp, 0, extent.yMaximum(), 0, -mupp])
@@ -240,6 +240,7 @@ def __init__(self, map_theme, layer, extent, tile_size, mupp, output,
240240
self.settings.setOutputImageFormat(QImage.Format_ARGB32)
241241
self.settings.setDestinationCrs(crs)
242242
self.settings.setOutputSize(self.image.size())
243+
self.settings.setBackgroundColor(QColor(255,255,255,0))
243244
self.settings.setFlag(QgsMapSettings.Antialiasing, True)
244245
self.settings.setFlag(QgsMapSettings.RenderMapTile, True)
245246

@@ -277,6 +278,10 @@ def renderTile(self, x, y, feedback):
277278
:param x: The x index of the current tile
278279
:param y: The y index of the current tile
279280
"""
281+
282+
background_colour = QColor(255,255,255,0)
283+
self.image.fill(background_colour.rgba())
284+
280285
painter = QPainter(self.image)
281286

282287
self.settings.setExtent(QgsRectangle(

0 commit comments

Comments
 (0)