Skip to content

Commit

Permalink
Added transparency to areas with no vector data.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Trashmonk authored and m-kuhn committed Dec 21, 2017
1 parent 9fe8729 commit 4fbea38
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/plugins/processing/algs/qgis/Rasterize.py
Expand Up @@ -21,7 +21,7 @@

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

from qgis.PyQt.QtGui import QImage, QPainter
from qgis.PyQt.QtGui import QImage, QPainter, QColor
from qgis.PyQt.QtCore import QSize
from qgis.core import (
QgsMapSettings,
Expand Down Expand Up @@ -228,7 +228,7 @@ def __init__(self, map_theme, layer, extent, tile_size, mupp, output,
xsize = self.x_tile_count * tile_size
ysize = self.y_tile_count * tile_size

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

Expand Down Expand Up @@ -277,6 +278,10 @@ def renderTile(self, x, y, feedback):
:param x: The x index of the current tile
:param y: The y index of the current tile
"""

background_colour = QColor(255,255,255,0)
self.image.fill(background_colour.rgba())

painter = QPainter(self.image)

self.settings.setExtent(QgsRectangle(
Expand Down

0 comments on commit 4fbea38

Please sign in to comment.