Skip to content
Permalink
Browse files

fix processing gdal_rasterize to allow write vector values in a exist…

…ing raster layer
  • Loading branch information
Giovanni Manghi
Giovanni Manghi committed Oct 21, 2014
1 parent 4bcde11 commit ee8b74f5ca6c0db2fde5cd22d8c2a62c83d74327
Showing with 20 additions and 14 deletions.
  1. +20 −14 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))
@@ -69,22 +73,24 @@ def defineCharacteristics(self):
self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))

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 ee8b74f

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