Skip to content
Permalink
Browse files

Merge pull request #1650 from gioman/gdal_rasterize_writeover

fix processing gdal_rasterize to allow write vector values in a existing raster layer
  • Loading branch information
alexbruy committed Oct 22, 2014
2 parents a4f2084 + d9b1638 commit 372c3ce8ac1d01812a2e85a6acd97fdc2e825484
Showing with 21 additions and 15 deletions.
  1. +21 −15 python/plugins/processing/algs/gdal/rasterize.py
@@ -31,6 +31,7 @@
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterBoolean
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils

@@ -42,6 +43,7 @@ class rasterize(GdalAlgorithm):
DIMENSIONS = 'DIMENSIONS'
WIDTH = 'WIDTH'
HEIGHT = 'HEIGHT'
WRITEOVER = 'WRITEOVER'
RTYPE = 'RTYPE'
OUTPUT = 'OUTPUT'

@@ -56,8 +58,10 @@ def defineCharacteristics(self):
self.addParameter(ParameterVector(self.INPUT, 'Input layer'))
self.addParameter(ParameterTableField(self.FIELD, 'Attribute field',
self.INPUT))
self.addParameter(ParameterBoolean(self.WRITEOVER,
'Write values inside an existing raster layer(*)', False))
self.addParameter(ParameterSelection(self.DIMENSIONS,
'Set output raster size', ['Output size in pixels',
'Set output raster size (ignored if above option is checked)', ['Output size in pixels',
'Output resolution in map units per pixel'], 1))
self.addParameter(ParameterNumber(self.WIDTH, 'Horizontal', 0.0,
99999999.999999, 100.0))
@@ -66,25 +70,27 @@ def defineCharacteristics(self):
self.addParameter(ParameterSelection(self.RTYPE, 'Raster type',
self.TYPE, 0))

self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))
self.addOutput(OutputRaster(self.OUTPUT, 'Output layer: mandatory to choose an existing raster layer if the (*) option is selected'))

def processAlgorithm(self, progress):
writeOver = self.getParameterValue(self.WRITEOVER)

arguments = []
arguments.append('-a')
arguments.append(str(self.getParameterValue(self.FIELD)))
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])

dimType = self.getParameterValue(self.DIMENSIONS)
if dimType == 0:
# size in pixels
arguments.append('-ts')
else:
# resolution in map units per pixel
arguments.append('-tr')
arguments.append(str(self.getParameterValue(self.WIDTH)))
arguments.append(str(self.getParameterValue(self.HEIGHT)))

if not writeOver:
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
dimType = self.getParameterValue(self.DIMENSIONS)
if dimType == 0:
# size in pixels
arguments.append('-ts')
else:
# resolution in map units per pixel
arguments.append('-tr')
arguments.append(str(self.getParameterValue(self.WIDTH)))
arguments.append(str(self.getParameterValue(self.HEIGHT)))

arguments.append('-l')
arguments.append(

0 comments on commit 372c3ce

Please sign in to comment.
You can’t perform that action at this time.